开发者

Set default content for target div

If this is my code, how do i set page1.html to show by default on page load?

Thanks in advance.

<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&g开发者_运维知识库t;
    </div>
</body>
</html>


If you want it to be loaded by javascript:

<body onload="swapContent('searchDiv', 'page1.html');"> 


You can add the onload event handler to thebody element:

 <body onload ="swapContent('searchDiv', 'page1.html');">
    ....

 </body>


How about calling swapContent('searchDiv', 'page1.html'); in onload of the body tag?


either put it in the onload event or depending on your framework you could include page1 inside the div in django it's

<div>{% include 'page1.html' %}</div>
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜