如何跳过领域使用javascript?
-
09-06-2019 - |
题
我有一个形式是这样的:
<form name="mine">
<input type=text name=one>
<input type=text name=two>
<input type=text name=three>
</form>
当用户类型中的一个值"一方",我有时想要跳场'two',根据什么他类型。例如,如果用户类型的'123',并使用标签移动到一个新的领域,我想跳过去领域有三个。
我试图用 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>
但没有这些工作。看起来像在浏览器不能让你混乱的焦点,而重点是变化的。
顺便说一句,所有这一尝试有Firefox在Linux。
解决方案
尝试将tabindex属性元素,然后programmaticaly(javaScript改变):
<INPUT tabindex="3" type="submit" name="mySubmit">
其他提示
你可以使用 onfocus 活动领域的两个,其将被称为当它收到的焦点。在这点领域1的价值应该是更新的和可以进行检查。
如果使用方法描述,以及他们的工作,重点也改变当用户击的领域,而不是标签。我可以向你保证,这将导致沮丧的用户。(为什么它不工作是超过我。)
相反,正如前面所说,更改tabindex的适当领域尽快的内容领域之一的变化。
<form name="mine">
<input type="text" name="one" onkeypress="if (mine.one.value == '123') mine.three.focus();" />
<input type="text" name="two">
<input type="text" name="three">
</form>
尝试 onkeypress
而不是的 onblur
.此外,上 onfocus
外地两个是你应该送到三个。我假设你不想让他们在两个如果一个是123,所以你可以只是检查两个的 onfocus
并送上来三个。
不隶属于 StackOverflow