带id的html标签可以直接使用吗?

时间:2016-09-02 03:13:46

标签: javascript html

具有唯一ID的Html标记可以直接用作名为id的变量吗?

代码:

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>Document</title>
</head>
<body>
    <input type="text" id="mytest">
</body>
    <script>
        console.log(mytest);
        console.log(mytest === document.getElementById('mytest'));
        console.log(Object.hasOwnProperty(window,'mytest'));

    </script>
</html>

输出: enter image description here

怎么会这样? mytest在哪里?

0 个答案:

没有答案
相关问题