【发布时间】:2013-12-06 10:37:32
【问题描述】:
我想了解 HTML 和 JS 函数的执行顺序。 代码:
<!DOCTYPE html>
<html>
<head>
<script>
function myFunction()
{
var x=document.getElementsByName("check1");
x[0].disabled=true;
x[0].checked=true;
x[0].value="Y";
}
function myFunction1()
{
var x=document.getElementsByName("check1");
alert(x[0].value);
}
</script>
</head>
<body onload="myFunction()">
<h1>Hello World!</h1>
<form>
<input type="checkbox" name="check1" unchecked enabled value="N"/>
<input type="button" value="Button" onclick="myFunction1()"/>
</form>
</body>
</html>
最后元素“check1”的值为=Y。 最后复选框被选中并禁用。 谁能解释一下。 我已经浏览了这个非常有用的链接: Load and execution sequence of a web page?
上面的例子仍然会有所帮助。谢谢
【问题讨论】:
-
你的函数名是一样的——myFunction()。您可能想将一个更改为 myFunction1()
-
为什么你定义了两个名为
myFunction的函数? -
我已经编辑了我的问题..
标签: javascript html execution