代码改变世界

我对onselect和onchange事件的误解

2012-07-06 14:52  江苏黑马  阅读(9006)  评论(0)    收藏  举报

很少用onselect事件,今天我才发现onselect事件:当选择一段文字的时候触发。以前我一直以为onselect和onchange都是是<select><option></option></select>内option元素切换的时候触发。是我误解了onselect事件。

 1 <!doctype html>
 2 <html>
 3 <head>
 4 <meta charset="utf-8">
 5 <title>exercise</title>
 6 <style></style>
 7 <script>window.onload=function(){
 8     document.getElementById("iptExercise").onselect=function(){
 9         alert("select");    
10     }
11     document.getElementById("iptExercise").onchange=function(){
12         alert("change");    
13     }
14 }
15 </script>
16 </head>
17 <body>
18 <input type="input" value="exercise" id="iptExercise" name="iptExercise">
19 </body>
20 </html>