<legend id='QEmw2'><style id='QEmw2'><dir id='QEmw2'><q id='QEmw2'></q></dir></style></legend>
<i id='QEmw2'><tr id='QEmw2'><dt id='QEmw2'><q id='QEmw2'><span id='QEmw2'><b id='QEmw2'><form id='QEmw2'><ins id='QEmw2'></ins><ul id='QEmw2'></ul><sub id='QEmw2'></sub></form><legend id='QEmw2'></legend><bdo id='QEmw2'><pre id='QEmw2'><center id='QEmw2'></center></pre></bdo></b><th id='QEmw2'></th></span></q></dt></tr></i><div id='QEmw2'><tfoot id='QEmw2'></tfoot><dl id='QEmw2'><fieldset id='QEmw2'></fieldset></dl></div>
    <tfoot id='QEmw2'></tfoot>

    <small id='QEmw2'></small><noframes id='QEmw2'>

      • <bdo id='QEmw2'></bdo><ul id='QEmw2'></ul>

      由于文本框 onblur 事件中的警报框导致按钮单击事

      时间:2023-08-08
      <i id='KmPy3'><tr id='KmPy3'><dt id='KmPy3'><q id='KmPy3'><span id='KmPy3'><b id='KmPy3'><form id='KmPy3'><ins id='KmPy3'></ins><ul id='KmPy3'></ul><sub id='KmPy3'></sub></form><legend id='KmPy3'></legend><bdo id='KmPy3'><pre id='KmPy3'><center id='KmPy3'></center></pre></bdo></b><th id='KmPy3'></th></span></q></dt></tr></i><div id='KmPy3'><tfoot id='KmPy3'></tfoot><dl id='KmPy3'><fieldset id='KmPy3'></fieldset></dl></div>
    1. <tfoot id='KmPy3'></tfoot>
        <bdo id='KmPy3'></bdo><ul id='KmPy3'></ul>

        <small id='KmPy3'></small><noframes id='KmPy3'>

        • <legend id='KmPy3'><style id='KmPy3'><dir id='KmPy3'><q id='KmPy3'></q></dir></style></legend>
            <tbody id='KmPy3'></tbody>

              • 本文介绍了由于文本框 onblur 事件中的警报框导致按钮单击事件丢失的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

                问题描述

                我创建了一个简单的 Web 表单,其中包含一个文本框和一个按钮.我已经捕捉到了文本框的onblur事件.

                I have created a simple web form, containing one text box and one button. I have captured the onblur event of the text box.

                <html xmlns="http://www.w3.org/1999/xhtml" >  
                <head runat="server">  
                    <title>Untitled Page</title>  
                    <script language="javascript" type="text/javascript">  
                    function onTextBoxBlur()  
                    {  
                        alert("On blur");  
                        return true;  
                    }  
                    </script>  
                </head>  
                <body>  
                    <form id="form1" runat="server">  
                    <asp:TextBox ID="TextBox1" runat="server" onblur="onTextBoxBlur();"></asp:TextBox>  
                    <asp:Button ID="Button1" runat="server" Text="Button" />  
                </form>  
                </body>  
                </html>
                

                当我在文本框中输入一些值并单击按钮时,会发生文本框的 onblur 事件,但不会发生按钮的 onclick 事件.而且,当我从 js 函数中删除警报框时,它工作正常.按钮单击事件的某些方式丢失了.我认为这是由于警报框.知道为什么会这样吗?

                When I enter some value in text box and click on the button, then the onblur event of textbox occurs, but the onclick of the button doesn't. And, when I remove the alert box from the js function then it works fine. Some how the button click is event is lost. I think it is due to the alert box. Any idea why is this so?

                推荐答案

                一个按钮的点击"有两个部分,鼠标向下和鼠标向上.当您将鼠标放在按钮上时,它会获得焦点 - 模糊文本框并触发警报.由于警报对话框是模态的,它们会暂停页面上的所有活动,因此按钮不会检测到鼠标向上并且您的点击不会完成.

                A "click" of a button has two parts, mouse down and mouse up. When you mouse down on the button, it gains focus - blurring the text box and firing your alert. Since alert dialogs are modal, they halt all activity on the page so the button doesn't detect the mouse up and your click doesn't complete.

                可以使用模糊事件中的计时器解决您的问题,并在按钮的 mousedown 事件中取消该计时器:

                It could be possible to work around your issue using a timer within the blur event, and cancelling that timer within the mousedown event of the button:

                var timer;
                function onTextBoxBlur()  
                {  
                    timer = window.setTimeout(function () { alert("On blur"); }, 0);  
                    return true;  
                }  
                
                function onButtonMouseDown()
                {
                    clearTimeout(timer);
                }
                

                这篇关于由于文本框 onblur 事件中的警报框导致按钮单击事件丢失的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!

                上一篇:Javascript 访问 Disqus 评论文本框? 下一篇:如何在悬停时更改文本框内容

                相关文章

                最新文章

                <small id='5P3wI'></small><noframes id='5P3wI'>

              • <tfoot id='5P3wI'></tfoot>

                  <legend id='5P3wI'><style id='5P3wI'><dir id='5P3wI'><q id='5P3wI'></q></dir></style></legend>

                      <bdo id='5P3wI'></bdo><ul id='5P3wI'></ul>

                  1. <i id='5P3wI'><tr id='5P3wI'><dt id='5P3wI'><q id='5P3wI'><span id='5P3wI'><b id='5P3wI'><form id='5P3wI'><ins id='5P3wI'></ins><ul id='5P3wI'></ul><sub id='5P3wI'></sub></form><legend id='5P3wI'></legend><bdo id='5P3wI'><pre id='5P3wI'><center id='5P3wI'></center></pre></bdo></b><th id='5P3wI'></th></span></q></dt></tr></i><div id='5P3wI'><tfoot id='5P3wI'></tfoot><dl id='5P3wI'><fieldset id='5P3wI'></fieldset></dl></div>