禁用提交按钮,直到填入输入字段 [英] Disable Submit button until Input fields filled in

查看:118
本文介绍了禁用提交按钮,直到填入输入字段的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

想知道是否有人可以用正确的方向指向我的下一段jquery。我想禁用提交按钮,直到我的输入字段被填充。



我想出了这个



< ($('#inputName,#inputEmail,#inputTel').val().length> 0($ document).ready(function(){
if ){
$(input [type = submit])。attr(disabled,false);
}
else {
$(input [type = submit])。attr(disabled,true);
}
});

但是该按钮被永久禁用,即使在填写所有文本输入字段之后。



还在学习Jquery,并没有使用它一段时间..所以任何指针赞赏



谢谢

解决方案

您的事件绑定仅在文档准备就绪。


$ b

$($ document $)$ / $> .ready(function(){
validate();
$('#inputName,#inputEmail,#inputTel')。change(validate);
});

函数validate(){
if($('#inputName')。val()。length> 0&&
$('#inputEmail') .val().length(> 0&&
$('#inputTel').val().length> 0){
$(input [type = submit]) .prop(disabled,false);
}
else {
$(input [type = submit])。prop(disabled,true);
}
}


Was wondering if anyone could point me in the right direction with the following piece of jquery. I want to disable the submit button until my input fields have been filled in.

I have come up with this

$(document).ready(function (){
 if ($('#inputName, #inputEmail, #inputTel').val().length > 0) {
  $("input[type=submit]").attr("disabled", "false");
 }
 else {
  $("input[type=submit]").attr("disabled", "true");
 }
});

but the button is permanently disabled, Even after filling in all the text input fields

Still learning Jquery and haven't used it for a while.. So any pointers appreciated

Thanks

解决方案

Your event binding is only on document ready.

So there is no listener when you change something.

Do this instead :

$(document).ready(function (){
    validate();
    $('#inputName, #inputEmail, #inputTel').change(validate);
});

function validate(){
    if ($('#inputName').val().length   >   0   &&
        $('#inputEmail').val().length  >   0   &&
        $('#inputTel').val().length    >   0) {
        $("input[type=submit]").prop("disabled", false);
    }
    else {
        $("input[type=submit]").prop("disabled", true);
    }
}

这篇关于禁用提交按钮,直到填入输入字段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆