jQuery 函数阻止表单提交
我正在这个网站上工作:http://dev.rjlacount.com/treinaAronson-test
我遇到的问题是联系表单(单击左上角的联系按钮将其滑动打开)。
我使用以下 jQuery 使联系表单在按 esc 按键或单击打开面板外部时滑动关闭:
$(document).bind({
keydown:function(e) {
if (e.keyCode == 27 ) {
$("#panel").slideUp("3000");
$("form#change-form-2")[0].reset();
$('#fade , .popup_block').fadeOut(function() {
$('#fade').remove(); //fade them both out
});
}
}, click: function(e) {
$("#panel").slideUp("3000");
}
});
$('#flip, #panel').bind('click', function(e){return false});
这适用于我需要它执行的操作,但禁用了提交按钮的功能。如果我右键单击任意位置,它也会导致面板关闭(尽管这是一个更小的问题)。我对 Javascript 还很陌生;有人介意帮助我防止这种情况禁用联系按钮的功能吗?
任何建议将不胜感激!
I'm working on this site: http://dev.rjlacount.com/treinaAronson-test
The problem I'm having is with the contact form (click the contact button on the top left to slide it open).
I'm using the following jQuery to cause the contact form to slide closed on esc key press or clicking outside of the open panel:
$(document).bind({
keydown:function(e) {
if (e.keyCode == 27 ) {
$("#panel").slideUp("3000");
$("form#change-form-2")[0].reset();
$('#fade , .popup_block').fadeOut(function() {
$('#fade').remove(); //fade them both out
});
}
}, click: function(e) {
$("#panel").slideUp("3000");
}
});
$('#flip, #panel').bind('click', function(e){return false});
This works for what I need it to do, but is disabling the functionality of my submit button. It is also (although this is a more minor issue) causing the panel to close if I right-click anywhere. I'm pretty new to Javascript; would anybody mind helping me prevent this from disabling the functionality of the contact button?
Any advice would be greatly appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
要使提交表单正常运行,请将“return false”更改为以下内容:这将允许表单正常运行,而不允许事件冒泡到文档。
To get the submit form to function normally, change "return false" to the following: this will allow the form to function normally without allowing the event to bubble to the document.
您可以设置
按钮
的disabled
属性:You can set the
disabled
attribute of thebutton
:如果将点击仅绑定到#content div 会怎样?那么您的 #contact div 中应该不会有任何问题。
What if you bind the click just to the #content div? Then there should not be any problems in your #contact div.