jQuery 表单提交
我的表单正常工作,我收到了来自它的电子邮件,但如果您点击提交而不输入数据,您会收到一个错误框,通知您必填字段 - 但是我的提交按钮保持灰色,所以即使您填写了这些内容字段,您无法在不刷新的情况下提交表单。
代码:
jQuery(document).ready(function() {
$('#success').hide();
$('#contactform').submit(function() {
var action = $(this).attr('action');
$('#contactform #submit').attr('disabled', 'disabled').after('<img src="images/ajax-loader.gif" class="loader" />');
$("#message").slideUp(750,function() {
$('#message').hide();
$.post(action, {
name: $('#name').val(),
email: $('#email').val(),
phone: $('#phone').val(),
subject: $('#subject').val(),
comments: $('#comments').val(),
verify: $('#verify').val()
},
function(data) {
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#contactform img.loader').fadeOut('fast',function(){$(this).remove()});
$('#contactform #submit').attr('disabled','');
if(data.match('success') != null) $('#submit').hide();
});
});
return false;
});
});
非常感谢任何帮助!
My form works as it should and i receive the emails from it but if you hit submit without entering data you get an error box informing you what you of required fields - however my submit button stays greyed out, so even if you then fill in those fields you cannot submit the form without a refresh.
code:
jQuery(document).ready(function() {
$('#success').hide();
$('#contactform').submit(function() {
var action = $(this).attr('action');
$('#contactform #submit').attr('disabled', 'disabled').after('<img src="images/ajax-loader.gif" class="loader" />');
$("#message").slideUp(750,function() {
$('#message').hide();
$.post(action, {
name: $('#name').val(),
email: $('#email').val(),
phone: $('#phone').val(),
subject: $('#subject').val(),
comments: $('#comments').val(),
verify: $('#verify').val()
},
function(data) {
document.getElementById('message').innerHTML = data;
$('#message').slideDown('slow');
$('#contactform img.loader').fadeOut('fast',function(){$(this).remove()});
$('#contactform #submit').attr('disabled','');
if(data.match('success') != null) $('#submit').hide();
});
});
return false;
});
});
Any help is much appreciated!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(4)
这是因为
disabled
属性是存在的。我的意思是,包含禁用属性会导致元素被禁用。替换:
为:
This is because the
disabled
attribute works by existence. By that I mean that the very inclusion of the disabled attribute causes the element to be disabled.Replace:
with:
这是因为提交按钮在您点击提交后被禁用:
如果验证失败,您应该重新启用它,如下所示:
This is because the submit button is disabled after you hit the submit:
you shoul re-enable it if the validation fails like this:
尝试使用 removeAttribute 函数。
我认为这会解决你的问题。
(如
和
是一样的。
使用removeAttribute将呈现类似
的内容,您的问题将得到解决)
Try using removeAttribute function.
I think it will solve your problem.
(As
<input type='text' disabled='disabled' ---->
and<input type='text' disabled --->
are same.Using removeAttribute will render something like
<input type='text' --->
and your problem will be solved)您是否检查过该脚本是否实际运行到应删除或更新属性的位置?
did you check if this script actually runs to the point where it should remove or update the attribute?