如何找出在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>