【发布时间】:2018-06-03 04:49:47
【问题描述】:
我试图了解 javascript 中的执行顺序。为什么body中的foo优先于head中的foo。不是先编译的head里的foo吗?
<head>
<meta charset="UTF-8">
<title>Hello</title>
<script type="text/javascript">
function foo() {
greeting = "hello from the head";
alert(greeting);
}
</script>
</head>
<body>
<div id="clickMe" onclick="foo()">Click me</div>
<script>
function foo() {
greeting = "hello from the body";
alert(greeting);
}
</script>
</body>
</html>
【问题讨论】:
标签: javascript function execution