在我的代码中,我在标题部分有以下 javascript 代码块
function validateForm(bid) {
switch (bid) {
case "submitIDSearch":
alert("submitIDSearch");
return false;
case "submitNameSearch":
alert("submitNameSearch");
return false;
}
}
function fKeyDown(e) {
var kc = window.event ? window.event.keyCode : e.which;
if (kc == 13) {
document.getElementById('submitNameSearch').click();
}
}
然后我有以下 HTML 代码块
<form name="checkAbsenceForm" method="post" action="absenceReport.htm" onsubmit="return validateForm(this.submited)">
<label class="q">ID * <input id="searchRUID" name="searchID" maxlength="9" /></label>
<input id="submitIDSearch" type="submit" value="Search ID" onclick="this.form.submited = this.id;" />
<hr />
<label class="q">First Name <input id="searchFirstName" name="searchFirstName" maxlength="23" onKeyDown="javascript:fKeyDown(event);"/></label>
<br />
<label class="q">Last Name * <input id="searchLastName" name="searchLastName" maxlength="23" onKeyDown="javascript:fKeyDown(event);" /></label>
<input id="submitNameSearch" type="submit" value="Search Name" onclick="this.form.submited = this.id;" />
</form>
发生的事情是,当我Enter在searchLastName
输入文本框中按下键时,两个警报消息框都会弹出。一个显示submitNameSearch
,另一个显示submitIDSearch
。submitNameSearch
是所需的事件,但submitIDSearch
不是,我认为默认情况下它会以某种方式触发。
请问当我在searchLastName输入文本框中按键时,是否有办法摆脱submitIDSearch
事件?Enter
非常感谢!