最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

JavaScript OnBlur event prevents HTML form from being submitted - Stack Overflow

programmeradmin0浏览0评论

Consider the following form:

<form action="/a" method="post"> 
    <input name="x" type="text" onblur="myonblur(e)" />
    <input name="y" type="text" />
    <input name="submit" type="submit" value="Submit" />
</form>

When focus is on element with name "x" and user presses submit button, onblur event fires but form is NOT submitted. Is there any way to make submit button work as expected if I have onblur events in my form?

Consider the following form:

<form action="/a" method="post"> 
    <input name="x" type="text" onblur="myonblur(e)" />
    <input name="y" type="text" />
    <input name="submit" type="submit" value="Submit" />
</form>

When focus is on element with name "x" and user presses submit button, onblur event fires but form is NOT submitted. Is there any way to make submit button work as expected if I have onblur events in my form?

Share Improve this question edited Oct 31, 2020 at 16:28 Brian Tompsett - 汤莱恩 5,89372 gold badges61 silver badges133 bronze badges asked Apr 13, 2009 at 1:56 ArtemArtem 7,43315 gold badges60 silver badges99 bronze badges
Add a ment  | 

2 Answers 2

Reset to default 3

Consider optimizing your onBlur() method so it takes less time to run. If your form is prevented from getting submitted, it might be because the onBlur() is too long and hangs the browser from doing anything else.

You can also use the onChange() method instead of onBlur(). That may work better for you.

Try adding

return true;

after calling your onBlur function. The problem you are facing with might be due to "return false" prevention of the event handlers.

发布评论

评论列表(0)

  1. 暂无评论