Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/79.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
Jquery 检查表单是否已提交_Jquery - Fatal编程技术网

Jquery 检查表单是否已提交

Jquery 检查表单是否已提交,jquery,Jquery,在我的网页中有一个表单,其中包含提交按钮(id=search)和预测按钮(id=predict)。若用户并没有提交表单,但点击了“预测”按钮,那个么它必须提醒表单并没有提交。如何在JQuery中检查表单是否已提交 $(document).ready(function(){ $('#Predict').click(function(){ if($('#search').submit()) { window.open

在我的网页中有一个表单,其中包含提交按钮(id=search)和预测按钮(id=predict)。若用户并没有提交表单,但点击了“预测”按钮,那个么它必须提醒表单并没有提交。如何在JQuery中检查表单是否已提交

$(document).ready(function(){ 
       $('#Predict').click(function(){
         if($('#search').submit()) {            
             window.open("ouput.php");

          }

      else {  
        alert("Please click search or upload button first \n\
             and then click Predict "); 
         }
    });
});

但警报框没有出现,即使表单未提交,output.php页面也会打开。

我不知道我是否正确理解了您的问题,这是否有助于您
但在此页面中,您有一个表单,当您提交表单时,脚本会添加一个类“确定预测”按钮。
当您单击“预测”按钮时,脚本会检查是否存在确定类
如果脚本未找到该类,则会显示一条警报消息

<!DOCTYPE HTML>
<html>
<head>
<meta charset="utf-8">
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.10.2/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
 $('#a').submit(function(){
    $('#predict').addClass('ok') 
    })
  $('#predict').click(function(){
    var clas=$(this).attr('class')  
    if(clas!=='ok'){
        alert('you must submit the form')
    }
  })
})
</script>

</head>
<body>
<form id="a" action="#">
    <input type="text" value="">
    <input type="submit" value="summit" id="search">
    <input type="button" value="predict" id="predict">
</form>
</body>
</html>

$(文档).ready(函数(){
$('#a')。提交(函数(){
$('#predict').addClass('ok'))
})
$('#predict')。单击(函数(){
var clas=$(this.attr('class'))
如果(clas!=='ok'){
警报('您必须提交表单')
}
})
})

使用表单上的.submit()检查是否已提交。将预测按钮设置为输入类型按钮(type=“button”)并将搜索按钮设置为输入类型提交(type=“submit”),现在只有搜索按钮将提交表单。您可以通过任何检查在predict click上提醒任何消息。我已经将搜索按钮类型设置为提交,但我的代码不起作用@我只使用了.submit()函数,但它不起作用。我的代码有什么问题吗@WilfredoP