[HTML/JS]利用JQuery的load函数动态加载其它页面的内容的实现代码代替Ifram


利用JQuery的load函数动态加载别的页面的代码,方便实时获取别的页面的内容。
基本语法为: $('#区域id').load('页面名称');

index.html
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>JQuery - Load</title>
    <link rel="stylesheet" media="all" type="text/css" href="../CSS/myStyle.css" />
    <script type="text/javascript" src="http://demo.jb51.net/jslib/jquery/jquery-1.3.2.min.js"></script>
    <style type="text/css">
        #header {
            margin-bottom: 1em;
            padding-bottom: 1em;
            border-bottom: 1px solid #eee;
        }

        .buttonListArea {
            float: left;
            width: 150px;
            padding-right: 10px;
            border-right: 1px solid #eee;
            margin-right: 10px;
        }

        .buttonArea {
            margin: 10px;
            padding-bottom: 20px;
        }

        #load_content {
            float: left;
            width: 550px;
            text-align: center;
        }
    </style>
    <script type="text/javascript">
        $(document).ready(function () {
            $('#btnLoad1').click(function () {
                $('#load_content').load('loadContent1.htm');
            });
            $('#btnLoad2').click(function () {
                $('#load_content').load('loadContent2.htm');
            });
            $('#btnLoad3').click(function () {
                $('#load_content').load('http://www.w3school.com.cn/jquery/ajax_load.asp');
            });
        });
    </script>
</head>
<body>
    <form id="form1" runat="server">
        <div id="container">
            <div id="header">
                <h2>JQuery Load Example</h2>
            </div>
            <div class="buttonListArea">
                <div class="buttonArea">
                    <button class="button" id="btnLoad1">Load 1</button>
                </div>
                <div class="buttonArea">
                    <button class="button" id="btnLoad2">Load 2</button>
                </div>

                <div class="buttonArea">
                    <button class="button" id="btnLoad3">Load 3</button>
                </div>
            </div>
            <div id="load_content">
                <h2>这是要被加载的区   域</h2>
            </div>
        </div>
    </form>
</body>
</html> 







loadContent1.htm

loadContent1.htm


loadContent2.htm

loadContent2.htm









评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值