[Jscript]填写Web表单时按回车键跳到下一个控件 |
flyby 发表于 2005/7/19 17:00:51 |
在制作web表单时,习惯了CS程序的用户总希望,按回车键可以自动跳到下一个控件。以下程序实现了这种功能。
<form id="form1" name="form1" method="post"> <br>text1<input name="input1" id=Text1 tabIndex=0><br>text2<input name="input2" id=Text2 tabIndex=0><br>text3<input name="input3" id=Text3 tabIndex=0> <br>Picture<img src="Iamge/logo.gif" tabIndex =-1><br>text4<input id=Img1 name="input4" id=Text4 tabIndex=0> <input id="Btn1" type="button" value="test" onclick="alert('你点击了按钮!');"> </form>
<script> function look(){ if(event.keyCode == 13) event.keyCode = 9; } document.onkeydown=look; form1.Text1.focus(); </script>
执行结果:首先光标停留在Text1内,当按回车键时,触发look函数,将回车键(13)替换成Tab键(9),这样就象按了tab键一样,光标将跳到Text2内,依次跳到Text3、Text4。因为Img1的tabindex属性为-1,小于0,而tabindex将从小到大一次跳转,所以不会跳到Img1上去。
我们可以自己设置tabindex的顺论,并设置那些不需要在tab键中到达的空间的tabindex为-1。
|
阅读全文(4409) | 回复(-1) | 编辑 | 精华 |
|
|
| « | December 2025 | » | | 日 | 一 | 二 | 三 | 四 | 五 | 六 | | 1 | 2 | 3 | 4 | 5 | 6 | 7 | 8 | 9 | 10 | 11 | 12 | 13 | 14 | 15 | 16 | 17 | 18 | 19 | 20 | 21 | 22 | 23 | 24 | 25 | 26 | 27 | 28 | 29 | 30 | 31 | | | | |
|
| 公告 |
此Blog中的文章仅代表本人当时观点,不对其正确性做任何担保。转载原创,请知会作者。QQ MSN | |
| Blog信息 |
|
blog名称:倾程记 日志总数:27 评论数量:72 留言数量:-3 访问次数:234819 建立时间:2005年7月8日
| |

|