gpt4 book ai didi

javascript - ASP.NET 按钮单击事件未触发

转载 作者:行者123 更新时间:2023-12-01 01:59:32 25 4
gpt4 key购买 nike

我在 div 中有一个按钮,默认情况下是隐藏的,因为它被 jQuery UI 用作模式弹出窗口。

这个按钮的点击事件处理程序永远不会被调用,但是如果我将按钮代码复制到这个隐藏的 div 之外,那么它就可以正常工作。我该如何解决这个问题?

这是我到目前为止的代码:

<div id="dialog" title="Notify Users">
<div style="width:100%; height:500px; overflow:auto;">
<asp:Repeater runat="server" ID="rptNotify">
<HeaderTemplate>
<table>
</HeaderTemplate>
<ItemTemplate>
<tr>
<td>
<asp:CheckBox ID="chkUser" runat="server" Checked='<%# Eval("Checked") %>' />
</td>
<td>
<asp:Label ID="lblUser" runat="server" Text='<%# Eval("FullName") %>'/>
</td>
</tr>
</ItemTemplate>
<FooterTemplate>
</table>
</FooterTemplate>
</asp:Repeater>
</div>
<asp:Button ID="btnSaveNotifications" runat="server" Text="Save" OnClick="btnSaveNotifications_Click" />
</div>

显示/隐藏此 div 的代码是:

<script>
// Increase the default animation speed to exaggerate the effect
$.fx.speeds._default = 1000;

$(function () {
$("#dialog").dialog({
autoOpen: false,
show: "blind",
hide: "explode"
});

$("#opener").click(function () {
$("#dialog").dialog("open");
return false;
});
});
</script>

最佳答案

这里的问题是 jQuery-UI 在 <form>外部创建了对话框。元素,因此单击它永远不会提交表单。

要解决此问题,您只需移动对话框 <div> 即可,而无需手动创建单击事件。回到表格中。我快速搜索了一下,答案是to this question已经涵盖了这个问题。

所以你只需要进行以下更改:

<script>
// increase the default animation speed to exaggerate the effect
$.fx.speeds._default = 1000;

$(function () {
var dialog = $("#dialog").dialog({
autoOpen: false,
show: "blind",
hide: "explode"
});

// Move the dialog back into the <form> element
dialog.parent().appendTo(jQuery("form:first"));

$("#opener").click(function () {
$("#dialog").dialog("open");
return false;
});
});
</script>

关于javascript - ASP.NET 按钮单击事件未触发,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7672890/

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