【发布时间】:2016-01-19 17:00:18
【问题描述】:
我有两个输入字段,分别是“电话”字段和“姓名”字段。我希望光标在“电话”字段仍然为空时保持焦点。因为当我在字段为空时单击“选项卡”时,会出现警报,并且在我单击“确定”后光标移动到“名称”字段。如果仍然是空的,如何使光标保持在“电话”上?
这是我的代码:
function whenEmpty(field) {
if (field.value == '') {
alert("Please fill the field.");
}
return false;
}
当我调用函数时:
<tr>
<td><div class="required"><label>Phone</label></div></td>
<td><form:input path="connote.shipperPhone" id="shipperPhone" name="shipperPhone"
onchange="loadCustomerData()" onfocus="this.select();" onmouseup="return false;" onblur="whenEmpty(this);"
htmlEscape="true" size="20" maxlength="50" tabindex="3"/> <form:errors
path="connote.shipperPhone" cssClass="error" /></td>
</tr>
【问题讨论】:
标签: javascript jquery jsp