最好用一个例子/伪代码解释
<html
<head></head>
include header.html
include content.html
include footer.html
</html>
header.html内容:
<script type="text/javascript">
$(document).ready(function(){
myFunction();
});
</script>
content.html内容:
<div id="myid">my contents here</div>
footer.html内容:
<script type="text/javascript">
function myFunction() {
$("#myid").hide();
console.log("im here");
}
我的问题是#myid永远不会被隐藏。我在浏览器控制台中看到“我在这里”所以我知道它正在运行。
如果我将header.html的内容移动到页面底部或div之后,它可以正常工作。
我假设document.ready仅在页面完全加载时运行/可用?
谢谢!
编辑:伪代码是网页的veryshort表示。实际页面中有500多行代码。