我遇到了问题,当我想在html标记中使用document.getElementById();
时。 例如=如何在javascript中优先执行dom
<html>
<head>
<script type="js"> //note this example is not found so browser is take time to execution
<script type="js"> //note this example is not found so browser is take time to execution
<script type="js"> //note this example is not found so browser is take time to execution
<script type="js"> //note this example is not found so browser is take time to execution
</head>
<body>
<div> ...
<div id="test">
</div>
</body>
</html>
我的问题是如何执行document.getElementById("test");
无需等待加载脚本没有发现?,可以使更多的time.how我可以修复this.thanks你的答案。
注:解决不删除或修改脚本到找到的目录。 以防万一,如果脚本没有找到。
任何其他建议的作品。我只想优先'document.getElementById(“test”);'是第一次执行,我可以得到innerHTML。 – viyancs
将你的JS文件加载到页面底部总是更好。看到为什么它最好加载在最后:http://stackoverflow.com/questions/1638670/javascript-at-bottom-top-of-web-page。请注意,没有' ',它应该是''script type =“text/javascript”src =“path/to/your/js/file”>' –
ah ya我已更新。 – viyancs