87,993
社区成员
发帖
与我相关
我的任务
分享<!doctype html>
<html>
<script>
console.log(window.b);
test2();
function test1(a)
{
console.log("test1");
console.log(window.b);
test2();
}
function test2()
{
console.log("test2");
console.log(window.b);
}
</script>
<body>
<div id="b" onclick="test1('b')">AAAAAA</div>
<div id="c" >AAAAAA</div>
<div id="b" >BBB</div>
</body>
</html>
[/quote]
这个我看的书比较少,你可以查一查,我只看了JS权威指南和head first js,权威指南挺好的,可以看一看
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="Generator" content="EditPlus®">
<meta name="Author" content="">
<meta name="Keywords" content="">
<meta name="Description" content="">
<script>
// 在页面加载之始,浏览器加载内容时即开始构造html dom对象,window、document等都在这个过程中产生
alert(window)
alert(document)
// 未加载的内容未必没有对象,比如document.title在初始之始就已经构造出来,但是空值
alert(document.title)
</script>
<title>Document</title>
<script>
// 当页面上部分特殊标签加载后,对应的html dom则进行赋值
alert(document.title)
</script>
</head>
<body>
<script>
// id 为 frm1 的控件未加载
alert(window['frm1'])
alert(document.forms.length)
</script>
<form id="frm1">
<script>
// id 为 frm1 的控件已加载
// 且该控件类型为 form ,追加到 document.forms 中
alert(window['frm1'])
alert(document.forms.length)
// frm1 表单中没有加载任何表单控件,长度为0
alert(document.forms[0].elements.length)
</script>
<input type="radio" name="rdo" id="rdo1" />
<script>
// 表单内容根据 name 更新至 document.forms 中
alert(document.forms[0].elements.length)
alert(document.forms[0].elements['rdo'])
</script>
<input type="radio" name="rdo" id="rdo2" />
<script>
// 表单内容根据 name 更新至 document.forms 中
alert(document.forms[0].elements.length)
alert(document.forms[0].elements['rdo'])
</script>
</form>
</body>
</html>
没什么诡异的地方