JS响应事件
<!DOCTYPE html> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>JS响应事件练习</title> <meta charset="utf-8" /> </head> <body> 用户名: <input type="text" /> <br /> <br /> <input type="button" value="确定" id="click" /> <script> document.write("<br/>"); btn = document.getElementById("click"); btn.onclick = function () { alert("HelloWorld!") } </script> <img src="a.jpg" id="a" /> <script> document.getElementById("a").onmouseover = function () { this.src = "b.jpg"; } document.getElementById("a").onmouseout = function () { this.src = "a.jpg"; } </script> <form id="form1" action="http://www.baidu.com"> 用户名:<input type="text" id="name" /> <br /> <br /> <input type="submit" /> <script> document.getElementById("form1").onsubmit = function () { name = document.getElementById("name").value; if (name =="") { alert("请输入用户名"); return false; } return name; } </script> </form> </body> </html>