我有一个这样的功能:
function whenEmpty(field) {
if (field.value == '') {
field.style.backgroundColor = "#ffcccc";
alert("Please fill the field.");
field.focus();
} else {
field.style.backgroundColor = "#ffff80";
}
}
Run Code Online (Sandbox Code Playgroud)
在我考虑这个想法之前(我想在按下 tab 键时调用这个函数。)我在属性 onblur 上调用这个函数。
<tr>
<td>
<div class="required">
<label>Phone</label>
</div>
</td>
<td>
<form:input path="connote.destPhone" id="destPhone" htmlEscape="true" onfocus="this.select();" onmouseup="return false;" onblur="whenEmpty(this);" style="background-color:#ffff80" size="20" maxlength="50" tabindex="9" />
<form:errors path="connote.destPhone" cssClass="error" />
</td>
</tr>
Run Code Online (Sandbox Code Playgroud)
但是现在我只想在按 Tab 键时调用该函数。