asp.net中的button.Onclick事件

时间:2015-02-06 16:19:58

标签: asp.net

我正在尝试做这样的事情:

<script type="text/javascript">
    $(document).ready(function () {
        $("#<%=InsertBtn.ClientID %>").click(function () {
            var respond = confirm("Press ok if you confirm");

            if (respond == true) {
                this.onclick = true;
            } else {
                this.onclick = false
            }
        });
    });
</script>

<asp:Button ID="InsertBtn" runat="server" Text="Insert" OnClick="InsertBtn_Click" />

如果用户回复错误,我怎么能禁用onclick事件?

1 个答案:

答案 0 :(得分:0)

好吧,我从互联网上找到了答案,

                <script type="text/javascript">
                    $(document).ready(function () {
                        $("#<%=InsertBtn.ClientID %>").click(function (e) {                                
                            var respond = confirm("Press ok if you confirm");

                            if (respond != true) {                    
                                e.preventDefault();
                            }
                        });
                    });
                </script>

                <asp:Button ID="InsertBtn" runat="server" Text="Insert" OnClick="InsertBtn_Click" />  

使用preventDefault()取消onclick默认操作