我有这样一个表格:
<form name="mine">
<input type=text name=one>
<input type=text name=two>
<input type=text name=three>
</form>
当用户在“一”中键入一个值时,我有时想跳过“二”字段,具体取决于他键入的内容。例如,如果用户键入“123”并使用 Tab 移至下一个字段,我想跳过它并转到第三个字段。
我尝试使用 OnBlur
和 OnEnter
,但没有成功。
尝试 1:
<form name="mine">
<input type=text name=one onBlur="if (document.mine.one.value='123') document.three.focus();>
<input type=text name=two>
<input type=text name=three>
</form>
尝试 2:
<form name="mine">
<input type=text name=one>
<input type=text name=two onEnter="if (document.mine.one.value='123') document.three.focus();>
<input type=text name=three>
</form>
但这些都不起作用。看起来浏览器不允许您在焦点发生变化时弄乱焦点。
顺便说一句,所有这些都在 Linux 上使用 Firefox 进行了尝试。
最佳答案
尝试将 tabindex 属性附加到您的元素,然后以编程方式(在 javaScript 中更改它):
<INPUT tabindex="3" type="submit" name="mySubmit">
关于javascript - 如何使用javascript跳过字段?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/79275/