我有一个带有 imageButton 的 Asp.net (Ver4) 网页,用于通过 imagebuttons 单击事件的代码将表单数据提交到数据库。在后面的代码中,我使用 response.redirect 将它们移动到感谢页面,它是后面的代码例程中的最后一行。 由于数据库有点慢,有时我想禁用点击事件,直到页面重定向。我正在尝试用 jquery 来做到这一点。我已经能够禁用该按钮并使其显示为禁用,但后面的代码根本不会触发。
这是我正在使用的 JQuery
function test() {
$("#ImageButton1").attr("disabled", "disabled").css('opacity',' 0.5');
}
这是按钮的 aspx 代码
<div class="button">
<asp:ImageButton ID="ImageButton1" runat="server" Height="28px"
OnClientClick="test();"
onclick="ImageButton1_Click"
ImageUrl="media/finishbutton.jpg"
style="margin-top: 0px" Width="97px" />
</div>
最佳答案
最简单的解决方案是在点击事件触发后稍后禁用该元素。例如:
function test() {
setTimeout(function () { $("#<%=ImageButton1.ClientID %>").attr("disabled", "disabled").css('opacity', ' 0.5'); }, 10);
}
关于JQuery 在代码隐藏执行之前禁用我的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12045152/