Ajax-02 iframe实现伪“Ajax”

需求:

  用户输入URL,使用iframe将目标URL的内容加载到页面指定位置(局部刷新)

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>使用iframe局部刷新</title>
</head>
<body>
<div>
    <p>请输入要加载的地址:<span id="currentTime"></span></p>

    <p>
        <input id="url" type="text">
        <input type="button" value="刷新" onclick="LoadPage();">
    </p>
</div>

<div>
    <h3>加载页面位置:</h3>
    <iframe id="iframePosition" style="width:100%;height: 500px;"></iframe>
</div>

<script>
    window.onload = function () {
        var myDate = new Date();
        document.getElementById('currentTime').innerText = myDate.getTime();

    };

    function LoadPage() {
        var targetUrl = document.getElementById('url').value;
        document.getElementById('iframePosition').src = targetUrl;
    }
</script>
</body>
</html>

 

posted @ 2017-04-07 18:29  鲨鱼逛大街  阅读(207)  评论(0编辑  收藏  举报