jQuery 中的 SimpleModal

发布于 2024-07-12 23:03:30 字数 1629 浏览 3 评论 0原文

我在 jQuery 中使用 SimpleModal,并使用 Ajax 来显示单选按钮。 它应该列出单选按钮和值。 单击单选按钮后, 该页面将被重定向到 page2。

当我在本地主机上测试它时,一切都很好。 但它不会重定向 Web 服务器上的页面。

我应该做出什么改变吗?

我的代码:

..............
$.ajax({
    url: 'test.php',
    cache: false,
    success: function(data) {
        $('#resp').modal({
            close: false,
            position: ["4%",],
            overlayId: 'confirmRespOverlay',
            containerId: 'confirmRespContainer',
            onShow: function (second) {
                second.data.find(".buttons .yes").hide();
                var resp = $("<div/>").append(data);
                var title = resp.find("#title").html(),
                message = resp.find("#message").html();
                second.data.find(".header span").html(title);
                second.data.find('.info').append(message);
                second.data.find('.yes').click(function () {
                });
            }//onShow
        }); //Resp

        $("input:radio").click(function() {
            var url="http://page2"
            window.location.replace(url);
        }); //input
    }//success
}); //ajax

test.php 返回以下

echo "<tr><td><input type=\"radio\" name=\"value_\" onClick=\"showUser(this.value)\" value=".$id1.">".$val1."</td><td>".$name."</td></tr>";

echo "<tr><td><input type=\"radio\" name=\"value_\" onClick=\"showUser(this.value)\" value=".$id2.">".$val2."</td><td>".$name."</td></tr>";

内容 单击单选按钮后页面停止并且不会移至下一页。 我该如何解决这个问题?

I am using SimpleModal in jQuery, and I use Ajax for displaying radio buttons.
It should list the radio button and values. After the radio button click,
the page is to be redirected to page2.

When I tested it on localhost, everything was fine. But it doesn't redirect
the page on the web server.

Any change I should make?

My code:

..............
$.ajax({
    url: 'test.php',
    cache: false,
    success: function(data) {
        $('#resp').modal({
            close: false,
            position: ["4%",],
            overlayId: 'confirmRespOverlay',
            containerId: 'confirmRespContainer',
            onShow: function (second) {
                second.data.find(".buttons .yes").hide();
                var resp = $("<div/>").append(data);
                var title = resp.find("#title").html(),
                message = resp.find("#message").html();
                second.data.find(".header span").html(title);
                second.data.find('.info').append(message);
                second.data.find('.yes').click(function () {
                });
            }//onShow
        }); //Resp

        $("input:radio").click(function() {
            var url="http://page2"
            window.location.replace(url);
        }); //input
    }//success
}); //ajax

test.php returns following

echo "<tr><td><input type=\"radio\" name=\"value_\" onClick=\"showUser(this.value)\" value=".$id1.">".$val1."</td><td>".$name."</td></tr>";

echo "<tr><td><input type=\"radio\" name=\"value_\" onClick=\"showUser(this.value)\" value=".$id2.">".$val2."</td><td>".$name."</td></tr>";

The page stopped after clicking the radio button and doesn't move to next page. How can I fix this problem?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

苦笑流年记忆 2024-07-19 23:03:31

在我看来,当您注册事件时,您的输入尚未添加。

有两个选项,一是在显示数据之前将数据加载到模式中(即绕过 onshow 方法),

$.ajax({ 
   url: 'test.php', 
   cache: false, 
   success: function(data) { 
       var second = $('#resp');
       second.data.find(".buttons .yes").hide();
       var resp = $("<div/>").append(data);
       var title = resp.find("#title").html();
       message = resp.find("#message").html();
       second.data.find(".header span").html(title);
       second.data.find('.info').append(message);
       second.data.find('.yes').click(function () {
       }); // click

       $('#resp').modal({
          close:false,
          position: ["4%",],
          overlayId:'confirmRespOverlay',
          containerId:'confirmRespContainer'
        }); //Resp

       $("input:radio").click(function() {
            var url="http://page2"
            window.location.replace(url);
       }); //input 

  }//success 

}); //ajax

或者在 onshow 方法内注册事件

$.ajax({ 
   url: 'test.php', 
   cache: false, 
   success: function(data) { 

       $('#resp').modal({
          close:false,
          position: ["4%",],
          overlayId:'confirmRespOverlay',
          containerId:'confirmRespContainer', 
          onShow: function (second) { 
                    second.data.find(".buttons .yes").hide();
                    var resp = $("<div/>").append(data);
                    var title = resp.find("#title").html();
                    message = resp.find("#message").html();
                    second.data.find(".header span").html(title);
                    second.data.find('.info').append(message);
                    second.data.find('.yes').click(function () {
                     });

                    $("input:radio").click(function() {
                      var url="http://page2"
                      window.location.replace(url);
                    }); //input 
          }//onShow

        }); //Resp

  }//success 

}); //ajax

It seems to me that your inputs haven't been added when you are registering the events.

There are two options one load your data into the modal before showing it (ie. bypassing your onshow method)

$.ajax({ 
   url: 'test.php', 
   cache: false, 
   success: function(data) { 
       var second = $('#resp');
       second.data.find(".buttons .yes").hide();
       var resp = $("<div/>").append(data);
       var title = resp.find("#title").html();
       message = resp.find("#message").html();
       second.data.find(".header span").html(title);
       second.data.find('.info').append(message);
       second.data.find('.yes').click(function () {
       }); // click

       $('#resp').modal({
          close:false,
          position: ["4%",],
          overlayId:'confirmRespOverlay',
          containerId:'confirmRespContainer'
        }); //Resp

       $("input:radio").click(function() {
            var url="http://page2"
            window.location.replace(url);
       }); //input 

  }//success 

}); //ajax

Or register your events inside the onshow method

$.ajax({ 
   url: 'test.php', 
   cache: false, 
   success: function(data) { 

       $('#resp').modal({
          close:false,
          position: ["4%",],
          overlayId:'confirmRespOverlay',
          containerId:'confirmRespContainer', 
          onShow: function (second) { 
                    second.data.find(".buttons .yes").hide();
                    var resp = $("<div/>").append(data);
                    var title = resp.find("#title").html();
                    message = resp.find("#message").html();
                    second.data.find(".header span").html(title);
                    second.data.find('.info').append(message);
                    second.data.find('.yes').click(function () {
                     });

                    $("input:radio").click(function() {
                      var url="http://page2"
                      window.location.replace(url);
                    }); //input 
          }//onShow

        }); //Resp

  }//success 

}); //ajax
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文