如何区分javascript提交和手动点击提交 [英] how to differentiate between javascript submit and manually clicking submit
本文介绍了如何区分javascript提交和手动点击提交的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何区分JavaScript触发的提交和手动点击表单提交
以下示例代码
how to differentiate between javascript triggered submit and manually clicking form submit
sample code below
function myfunction()
{
document.getElementById("id_searchform").submit();
return true;
}
形式:
<div class='row'>
<div class='col-md-4'>
<div class='clszipcode' ><span>Enter Zipcode</span></div>
</div>
<div class='col-md-4'>
<div class='clstxtzipcode' ><input type="text" name="zip_code" id="txtZipcode"></div>
</div>
<div class='col-md-4'>
<div class='clsbtnzip' ><input type="submit" name="submit" id="btnSearch" value="Search" class="button_example" ></div>
</div>
</div>
<a href="#" onclick="return myfunction();" >click to submit</a>
推荐答案
让我看看我是否明白:
- 您想要检测用户是否点击了提交表单的链接。
- 您想要检测
- 您有另一个名为
validate()
的函数,它将以某种方式使用这些信息。
- You want to detect whether the user clicked the link to submit the form.
- You want to detect if the user clicked the submit button to submit the form.
- You have another function called
validate()
which will use this information in some way.
如果是这种情况,请考虑使用变量来存储链接是否在触发表单提交之前被点击。 p>
If this is the case, consider using a variable to store whether the link was clicked before triggering the form to submit.
- 初始化全局变量
wasClicked
到false
- 点击链接时设置
wasClicked
到true
- 设置
wasClicked
后触发表单提交。 - 运行
validate $
c> validate()
- Initialize global variable
wasClicked
tofalse
- When link is clicked set
wasClicked
totrue
- Trigger form submit after
wasClicked
is set. - Run
validate()
when form is submitted - Check
if(wasClicked){...}
invalidate()
这里是工作示例
这篇关于如何区分javascript提交和手动点击提交的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文