gpt4 book ai didi

javascript - 为什么我的 Jquery Modals 会通过模态上的任何按钮关闭?

转载 作者:行者123 更新时间:2023-11-28 20:47:43 27 4
gpt4 key购买 nike

我的 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>

*我是否将返回值设置为 false?在正确的地方?:如果我在,结果仍然没有变化! *

   <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>

最佳答案

是的,你的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;
});

该按钮正在提交,这就是网络表单的本质。使用preventDefault (或者 return false; 如果需要的话),将阻止它发布到服务器,这是 asp:Button 的默认操作.

关于javascript - 为什么我的 Jquery Modals 会通过模态上的任何按钮关闭?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13146218/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com