[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









  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
<!DOCTYPE html> <html lang="en" xmlns:th="http://www.w3.org/1999/xhtml"> <head> <title>register</title> <script th:src="@{/js/jquery-2.1.1.min.js}" type="text/javascript"></script> <script th:src="@{/js/vue.min.js}" type="text/javascript"></script> <script src="https://unpkg.com/element-ui/lib/index.js"></script> <title>登录表单</title> <meta name="keywords" content="登录表单"/> <!-- Meta-Tags --> <meta name="viewport" content="width=device-width, initial-scale=1"> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <script type="application/x-javascript"> addEventListener("load", function() { setTimeout(hideURLbar, 0); }, false); function hideURLbar(){ window.scrollTo(0,1); } </script> <!-- //Meta-Tags --> <!-- Style --> <link rel="stylesheet" href="/./css/style.css" type="text/css" > </head> <body> <h1>注册表单</h1> <div class="container w3layouts agileits"> <div class="register w3layouts agileits" id="app"> <h2>注 册</h2> <form action="#" method="post"> <input type="text" Name="Name" placeholder="用户名" required=""> <input type="text" Name="Email" placeholder="邮箱" required=""> <input type="password" Name="Password" placeholder="密码" required=""> <input type="text" Name="Phone Number" placeholder="手机号码" required=""> </form> <div class="send-button w3layouts agileits"> <button @click="turnToRegister">注册</button> </div> <div class="clear"></div> </div> <div class="clear"></div> </div> <script> //新建一个Vue对象。 new Vue({ //绑定作用域 el: "#app", //绑定数据 data: {//双向绑定数据 user: { name: "", password: "", } }, //绑定方法; methods: { addOne() { //适用ajax进行数据交互 $.ajax({ url: "/user/insertOne",//请求的路径 type: "post",//请求的方式 data: { name: this.user.name,//获取user里面的数据并且进行绑定; password: this.user.password, }, //返回数据的格式 dataType: "json", //成功返回方式 success: function (rs) { if (rs.status == 200) {//rs获取状态码看是否成功 layer.alert(rs.msg, {icon: 6}, function () { //获取ifram层的窗口名 var frameIndex = parent.layer.getFrameIndex(window.name); parent.layer.close(frameIndex); parent.location.reload() location.href="/login" }) } else { layer.alert(rs.msg, {icon: 5}, function () { //获取ifram层的窗口名 var frameIndex = parent.layer.getFrameIndex(window.name); parent.layer.close(frameIndex); }) } } }) } } }) </script> </body> </html> 帮我以上代码实现注册功能成功后,新增一个小弹窗,弹窗内容是注册成功
最新发布
05-24

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值