jQuery Stop .blur()事件当点击“提交”按键 [英] jQuery Stop .blur() event when clicking "submit" button
问题描述
我正在建立一个简单的演示电子邮件注册表单的小型着陆页。我想要在聚焦时打开表单字段,然后缩小模糊。
I am building a small landing page with a simple demo e-mail signup form. I want to have the form field open up when focused, and then shrink back down on blur.
然而,我遇到的问题是当您单击提交按钮时,会启动模糊功能,隐藏按钮并缩小表单。我需要找到一种方法来停止.blur()方法,只有当用户点击聚焦在提交按钮。有没有什么好的解决方法?
However the problem I'm facing is when you click the submit button this instigates the blur function, hiding the button and shrinking the form. I need to find a way to stop the .blur() method only when the user is clicking to focus on the submit button. Is there any good workaround for this?
感谢任何帮助我可以得到!
Would appreciate any help I can get!
推荐答案
它不是最漂亮的解决方案,但它确实有效。尝试这样:
It isn't the prettiest solution, but it does work. Try this:
$("#submitbtn").mousedown(function() {
mousedownHappened = true;
});
$("#email").blur(function() {
if (mousedownHappened) // cancel the blur event
{
mousedownHappened = false;
}
else // blur event is okay
{
$("#email").animate({
opacity: 0.75,
width: '-=240px'
}, 500, function() {
});
// hide submit button
$("#submitbtn").fadeOut(400);
}
});
这篇关于jQuery Stop .blur()事件当点击“提交”按键的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!