如何填写表单之前禁用提交按钮 [英] how to disable submit button until form is filled
问题描述
我知道那里有很多答案,但由于某种原因,它不适合我。
您可以在 JSFiddle
脚本的位置有错误吗?与其中一个输入ID?
问题:填充文本字段后,该按钮仍然禁用。
HTML
< form class =formname =contactformmethod =postaction =https:/ /lp.outit.co.il/LA-FACE/send_form_email.php\">
< input placeholder =Your Name *type =textname =namemaxlength =50>
< input placeholder =Phone *type =textname =telephonemaxlength =30>
< input placeholder =Email *type =emailname =emailmaxlength =80>
< input class =sendid =registertype =submitvalue =Senddisabled =disabled>
< p> * =要求栏位< / p>
< / form>
JQUERY ON HEAD
< script src =http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js>< / script>
< script>
(function(){
$('form> input')。keyup(function(){
var empty = false;
$('form > input')。each(function(){
if($(this).val()===''){
empty = true;
}
});
if(empty){
$('#register')。attr('disabled','disabled');
} else {
$('#register')。removeAttr('disabled');
}
});
})();
< / script>
我张贴工作小提琴,这是你想要的吗? http://jsfiddle.net/qqwcu/2/
注意它最好使用: $('#register')。prop(disabled,false);
检查使用JQuery删除禁用的属性?
<$ (函数()){
$('form> input')。 empty1 = false;
$('form> input')。each(function(){
if($(this).val()===''){
empty1 = true;
}
});
if(empty1){
$('#register')。attr('disabled','disabled') ;
} else {
$('#register')。prop(disabled,false);
}
});
} );
I know there is a lot answers for that out-there, but from some reason it not working for me.
You can view the code on JSFiddle
There is mistake on the position of the script? with one of the inputs id ?
The problem: after fill the text fields, the button still disabled.
HTML
<form class="form" name="contactform" method="post" action="https://lp.outit.co.il/LA-FACE/send_form_email.php">
<input placeholder="Your Name*" type="text" name="name" maxlength="50">
<input placeholder="Phone *" type="text" name="telephone" maxlength="30">
<input placeholder="Email *" type="email" name="email" maxlength="80">
<input class="send" id="register" type="submit" value="Send" disabled="disabled">
<p>* = Requierd fields</p>
</form>
JQUERY ON HEAD
<script src="http://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<script>
(function() {
$('form > input').keyup(function() {
var empty = false;
$('form > input').each(function() {
if ($(this).val() === '') {
empty = true;
}
});
if (empty) {
$('#register').attr('disabled', 'disabled');
} else {
$('#register').removeAttr('disabled');
}
});
})();
</script>
I posted working fiddle ,Is this what u want ? http://jsfiddle.net/qqwcu/2/
Note its preferred to use: $('#register').prop("disabled", false);
Check this Remove disabled attribute using JQuery?
$(document).ready(function(){
$('form > input').keyup(function() {
var empty1 = false;
$('form > input').each(function() {
if ($(this).val() === '') {
empty1 = true;
}
});
if (empty1) {
$('#register').attr('disabled', 'disabled');
} else {
$('#register').prop("disabled", false);
}
});
});
这篇关于如何填写表单之前禁用提交按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!