1 <!DOCTYPE html>
2 <html lang="en">
3 <head>
4 <meta charset="UTF-8">
5 <title>表单事件</title>
6 </head>
7 <body>
8 <form action="">
9 <input type="text" name="usr">
10 <button type="submit">提交</button>
11 <div></div>
12 </form>
13 </body>
14 <script type="text/javascript">
15 var form = document.querySelector('form')
16 var ipt = document.querySelector('input')
17 var btn = document.querySelector('button')
18 ipt.onselect = function () {
19 console.log('文本被选中');
20 };
21 var div = document.querySelector('div')
22 // ipt.oninput = function () {
23 // console.log('值改变');
24 // div.innerText = this.value
25 // };
26 // ipt.onkeyup = function () {
27 // div.innerText = this.value
28 // }
29 // ipt.onchange = function () {
30 // div.innerText = this.value
31 // }
32 form.onsubmit = function () {
33 console.log('提交')
34 return false;
35 }
36
37 </script>
38 </html>