0

但是,我的 Jquery 模态运行完美,当我单击一个不应该关闭模态的按钮时,它会关闭模态吗?难道是按钮正在自动刷新页面导致模式关闭?我怎样才能克服这个当前的问题?

这是脚本:

 <script>

$(document).ready(function () {
    var triggers = $(".modalInput").overlay({

        // some mask tweaks suitable for modal dialogs
        mask: {
            color: '#F7F7F7',
            loadSpeed: 200,
            opacity: 0.9
        },

        closeOnClick: false
    });

    var buttons = $("#yesno button").click(function (e) {

        // get user input
        var yes = buttons.index(this) === 0;

        // do something with the answer
        triggers.eq(0).html("You clicked " + (yes ? "yes" : "no"));
    });

});

 </script>

这是按钮(触发器):

    <asp:Button class="modalInput" rel="#yesno" ID="modalInput" runat="server" BackColor="#525663" BorderColor="#999999"
               BorderStyle="Solid" BorderWidth="1pt" CommandName="MoveNext" Font-Size="Large"
               ForeColor="White" Style="font-family: Segoe UI; margin-left: 0px; position: relative;
               top: 25px; left: -25px; width: 152px; height: 41px;" Text="Edit Information"  />

这是模态:

  <div class="modal" id="yesno">  
 <h2>Edit Account Information:</h2>  

   <Uc2:EditCurrentSet ID="EditCurrentSet" runat="server" />

    <a class="close"></a> 

        </p></div> 

*我是否将返回错误;在正确的地方?:如果我在,结果仍然没有变化!*

   <script>


$(document).ready(function () {
    var triggers = $(".modalInput").overlay({

        // some mask tweaks suitable for modal dialogs
        mask: {
            color: '#F7F7F7',
            loadSpeed: 200,
            opacity: 0.9
        },

        closeOnClick: false

    });

    var buttons = $("#yesno button").click(function (e) {

        // get user input
        var yes = buttons.index(this) === 0;

        // do something with the answer
        triggers.eq(0).html("You clicked " + (yes ? "yes" : "no"));
        return false;
    });

    return false;
});
  </script>
4

2 回答 2

2

是的,你return false;来错地方了。而不是return false;,使用事件的preventDefault功能:

var buttons = $("#yesno button").click(function (e) {
    e.preventDefault();

    // get user input
    var yes = buttons.index(this) === 0;

    // do something with the answer
    triggers.eq(0).html("You clicked " + (yes ? "yes" : "no"));
    return false;
});

该按钮按 Web 表单的性质提交。使用preventDefault(或return false;如果您愿意),将阻止它发布到服务器,这是asp:Button.

于 2012-10-30T19:46:30.267 回答
1

如果您已将事件处理程序更改为返回 false 并且它仍然无法正常工作,那么您没有选择正确的按钮。我认为您的选择器应如下所示:

var buttons = $("#modalInput").click(function (e) {
    // get user input
    var yes = buttons.index(this) === 0;

    // do something with the answer
    triggers.eq(0).html("You clicked " + (yes ? "yes" : "no"));
    return false;
});

选择器中的 # 表示您正在尝试按 ID 查找按钮 - 您可以查看该按钮的呈现 HTML(在您喜欢的浏览器中查看源代码/Web 开发人员工具)并自己检查 ID。通过向按钮添加一个 rel 属性,您已经使它有点复杂了,但我不会想到选择器无论如何都会起作用。

于 2012-10-30T19:30:17.883 回答