我正在制作一个不改变页眉和页脚的网站。当单击站点时,主div将被更改。以下是代码:
<p id="item1">Item 1</p>
...
<script>
$("#item").click(function(){$("#main").load("item1.html");});
</script>在项目1.html中:
<div id="sth"></div>
...
<script>
window.onload = function() {document.getElementById("sth").style.width = ...
</script>当我单独打开它(url = mywebsite.com/ Item1.html )时,Item1.html工作得很好。但是,当我用上面的脚本(index.html)启动它时,window.onload函数就不能工作了。我怎么才能修好它?
发布于 2015-08-08 01:40:57
您可以使用.load成功回调函数,如下所述
$("#item").click(function(){
$("#main").load("item1.html", function(){
// your logics here
document.getElementById("sth").style.width =...
});
});您可以理解window.onload的使用
https://stackoverflow.com/questions/31888730
复制相似问题