如果这是我的代码,如何在页面加载时将page1.html设置为默认显示?
提前致谢。
<head>
<title>Test</title>
<meta http-equiv="content-type" content="text/html; charset=UTF-8">
<script type="text/javascript">
function swapContent(targetID, url) {
var target = document.getElementById(targetID);
var ajax = new XMLHttpRequest();
ajax.open('GET', url, true);
ajax.onreadystatechange = function() {
if(ajax.readyState == 4) {
target.innerHTML = ajax.responseText;
}
}
ajax.send(null);
}
</script>
</head>
<body>
<div>
<div>
<a href="javascript: void();" onclick="swapContent('searchDiv', 'page1.html');">First</a> |
<a href="javascript: void();" onclick="swapContent('searchDiv', 'page2.html');">Second</a> |
<a href="javascript: void();" onclick="swapContent('searchDiv', 'page3.html');">Third</a>
</div>
<hr>
<div id="searchDiv" style="width: 550px; height: 400px; overflow: scroll;">Please select one...</div>
</div>
</body>
</html>
答案 0 :(得分:2)
如果您希望通过javascript加载它:
<body onload="swapContent('searchDiv', 'page1.html');">
答案 1 :(得分:1)
如何在swapContent('searchDiv', 'page1.html');
代码的onload
中调用body
?
答案 2 :(得分:1)
您可以将onload事件处理程序添加到body元素:
<body onload ="swapContent('searchDiv', 'page1.html');">
....
</body>
答案 3 :(得分:1)
要么把它放在onload事件中,要么根据你的框架你可以在django中包含div里面的page1
<div>{% include 'page1.html' %}</div>