为你而来

javascript事件

onchange,用户改变域的内容,所以存在type='text' select textarea中 要等失去焦点时

onchange事件,和下拉列表<select>是有关系的,当其值因选定又改变时产生onchange事件

1 <html>
2 <head>
3 </head>
4 <body>
5 <input type='text' onchange='alert(this.value);'/>
6 
7 </body>
8 </html>

注意和onkeydown比较,onkeydown每按下一键,便产生一次事件,而用onchang要等到失去焦点,才会生成事件,所以它被用来注册页面
的验证,而要ajax做个智能提示,则只能用onkeydown

1 <html>
2 <head>
3 <title>1</title>
4 </head>
5 <body>
6 <input type='text' onkeydown="var c=document.title;c=Number(c);c++;document.title=c;"/>
7 
8 </body>
9 </html>

onselect跟<select>标签没有关系,是一个选定文本的事件,每选定一个字符便触发一次,所以选定“hello”,就触发5次

可以复制该段代码,试一下

1 <html>
2 <head>
3 <title>1</title>
4 </head>
5 <body>
6 <input type='text' onselect="var c=document.title;c=Number(c);c++;document.title=c;"/>
7 
8 </body>
9 </html>

 

posted on 2012-06-03 22:25  为你而来  阅读(162)  评论(0编辑  收藏  举报

导航