Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/443.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
使用标志来';继续';用javascript?_Javascript_Jquery - Fatal编程技术网

使用标志来';继续';用javascript?

使用标志来';继续';用javascript?,javascript,jquery,Javascript,Jquery,我只想在填写完所有字段后触发submit_form函数。现在将触发提交表单 $(“#提交”)。单击(函数(){ $('body input')。每个(函数(){ if($(this.val()=''){ 警报('请填写'+$(this.attr('占位符')); $(this.focus(); 返回false; } }) 提交表格(); }); 函数提交表单(){ 警报(“转到sumbit表单”); } 提交 好的,根据您的代码,您的提交函数始终会调用,因此我为其添加了一个标志,

我只想在填写完所有字段后触发submit_form函数。现在将触发提交表单

$(“#提交”)。单击(函数(){
$('body input')。每个(函数(){
if($(this.val()=''){
警报('请填写'+$(this.attr('占位符'));
$(this.focus();
返回false;
}
})
提交表格();
});
函数提交表单(){
警报(“转到sumbit表单”);
}







提交
好的,根据您的代码,您的提交函数始终会调用,因此我为其添加了一个标志,请检查

$('#submit').click(function() {
    var flag = 1;
    $('body input').each(function() {
        if ($(this).val() == '')
        {
            alert('Please fill in ' + $(this).attr('placeholder'));
            $(this).focus();
            flag = 0;
            return false;
        }
    })
    if(flag)
    {
        submit_form();
    }
});

当一个输入字段为空时,使用标志阻止提交表单

$(“#提交”)。单击(函数(){
this.canSend=true;
$('body input')。每个(函数(){
if($(this.val()=''){
this.canSend=false;
警报('请填写'+$(this.attr('占位符'));
$(this.focus();
返回false;
}
})
if(this.canSend){
提交表格();
}
});
函数提交表单(){
警报(“转到sumbit表单”);
}







提交
试试这个

$(“#提交”)。单击(函数(){
var标志=1;
$('body input')。每个(函数(){
if($(this.val()='')
{
警报('请填写'+$(this.attr('占位符'));
$(this.focus();
flag=0;
返回false;
}
其他的
{
flag=1;
}
})
国际单项体育联合会(旗)
{
提交表格();
}
});
函数提交表单(){
警报(“转到sumbit表单”);
}







提交
删除所有JavaScript

<body>
  <input type="text" placeholder="name" required>
  <br>
  <br>
  <input type="text" placeholder="hp" required>
  <br>
  <br>
  <input type="email" placeholder="email" required>
  <br>
  <br>
  <button id="submit">Submit</button>
</body>







提交
您的表格在哪里?问题是什么?@rahul submit form是function@hindmostrequiremannt:在填写完所有表单后提交表单,否则请提醒未填写的表单。您的代码到底出了什么问题?我更新了他的答案。如果($(this).val()=''){alert,则他缺少小的else条件('Please fill in'+$(this.attr('placeholder'));$(this.focus();flag=0;return false;}否则{flag=1;}现在它的工作完成了。你的小提琴错了。看我在哪里设置了“var flag=1;”@佐提:不需要别的了condition@NingSia你检查过了吗?提交没有值的表单意味着标志集falg=0,然后你输入值submit,同时也输入标志=0,然后表单如何提交?所以需要其他条件@rahul working fiddle