【问题标题】:Could jquery's dialog modal change page inside modal?jquery的对话框模式可以改变模式内的页面吗?
【发布时间】:2016-12-22 05:09:03
【问题描述】:

您好,我尝试让 jquery 对话框弹出(模式)可以更改为弹出窗口中的其他页面(在现有弹出窗口中加载其他页面)

但我不知道如何通过在 test2.php 中编码来在模态中加载 test3.php

这是我的尝试

test1.php

 <!doctype html>
<html lang="en">
<head>
  <meta charset="utf-8">
  <meta name="viewport" content="width=device-width, initial-scale=1">
  <title>jQuery UI Dialog - Default functionality</title>
  <link rel="stylesheet" href="//code.jquery.com/ui/1.12.1/themes/base/jquery-ui.css">
  <link rel="stylesheet" href="/resources/demos/style.css">
  <script src="https://code.jquery.com/jquery-1.12.4.js"></script>
  <script src="https://code.jquery.com/ui/1.12.1/jquery-ui.js"></script>

</head>
<body>
 <button id="btn">Click to Popup</button>

<div id="dialog" title="Basic dialog">
  here 
</div>
 <script>
    $(function () {
        $("#dialog").dialog({
            open: function(event, ui) {
             $('#dialog').load('test2.php', function() {
               alert('Load was performed.');
             });
           },
            modal: true,
            autoOpen: false,
            title: "jQuery Dialog",
            width: 600,
            height: 350
        });

    $("#btn").click(function(){
        $('#dialog').dialog('open');
    });
    });
 </script>


</body>
</html>

test2.php

this is test2.php page <br/>
<a href="test3.php"> Go to Page test3.php </a>

test3.php

<p> this is test3.php page </p>

【问题讨论】:

  • 检查您的浏览器控制台..您看到任何错误吗?
  • 不不,我只是不知道如何在 test2.php 页面中编写代码 .load(),因为在 test2.php 中只有 2 行代码

标签: javascript jquery jquery-ui jquery-ui-dialog


【解决方案1】:

在 test1.php 中试试这个

$(function () {
    $("#dialog").dialog({
        open: function(event, ui) {
        $('#dialog').load('test2.php', function() {
            $('#mylink').click(function(){
                $('#dialog').load('test3.php', function() {
                      alert('Load was performed.');
                });
             });
         });
       },
        modal: true,
        autoOpen: false,
        title: "jQuery Dialog",
        width: 600,
        height: 350
    });

    $("#btn").click(function(){
        $('#dialog').dialog('open');
    });
});

test2.php

this is test2.php page <br/>
<button id="mylink">Go to Page test3.php</button>

【讨论】:

  • 但我认为如果它有多个页面,将很难编写许多匿名函数,所以我只是在 test2.php 页面中编写事件点击并加载 test3.php 的编码并包含 jquery-ui.js在 page2 中。
  • 是的,不需要在page2中包含jquery-ui.js
【解决方案2】:

尝试使用以下代码:

$(document).ready(function() { 

     var dlg=$('#dialog').dialog({
        title: "jQuery Dialog",
        resizable: true,
        autoOpen:false,
        modal: true,
        hide: 'fade',
        width:350,
        height:275
     });


     $('#btn').click(function(e) {
         e.preventDefault();
         dlg.load('test3.php', function(){
             dlg.dialog('open');
         });
      }); 
});

【讨论】:

  • 不不,我只是不知道如何在 test2.php 页面中编写代码 .load(),因为在 test2.php 中只有 2 行代码
  • 我想在test2.php中加载test3.php
  • 在load()中添加页面名称(test3.php)
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2011-12-03
  • 1970-01-01
  • 2011-02-07
  • 1970-01-01
  • 1970-01-01
  • 2012-03-23
相关资源
最近更新 更多