我怎样才能知道在javascript中点击了哪个提交按钮?
function submitForm(){
//if find open popup
//else if add continue in the same window
}
<form action="/findNames" onsubmit="return submitForm()">
<input type="submit" value="Add" onclick="submitForm(this)"/>
<input type="submit" value="Find" onclick="submitForm(this)"/>
</form>
我已经尝试过:
我尝试使用 onclick 来执行此操作,如下所示,但是当单击“查找”按钮时,它会打开一个弹出窗口并提交父窗口。如何阻止它提交父窗口?
function submitForm(submit){
if(submit.value=="Find"){
find();//opens a popup window
}else if(submit.value == "Add"){
//stay in the same window
}
}
function find(){
var width = 1010;
var height = 400;
var params = 'width='+width+', height='+height;
popupWin = window.open('find.do','windowname5', params);
popupWin.focus();
}
<form action="/findNames">
<input type="submit" value="Add" onclick="submitForm(this)"/>
<input type="submit" value="Find" onclick="submitForm(this)"/>
</form>
An input
of type="submit"
将始终提交表格。使用input
of type="button"
相反,创建一个不提交的按钮。
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)