document.links[i].onclick;展示表单的输入
<html> <head> <title>8-7</title> <script language="javascript"> function HandleAllLinks() { for(var i = 0; i < document.links.length; i++) { document.links[i].onclick = HandleLink; } } function HandleLink() { alert("即将离开当前页面!"); } </script> </head> <body onload="HandleAllLinks()"> <li><a href="范例8-1.html">范例8-1</a></li> <li><a href="范例8-2.html">范例8-2</a></li> </body> </html>
展示表单的输入:
<html> <head> <title>8-6</title> </head> <body> <form id="form1" name="form1" method="post" action=""> <label>姓名: <input type="text" name="textfield" /> </label> <p> <label>密码: <input type="password" id="password" name="textfield2" /> </label> <p> <input type="submit" name="Submit" value="查看密码和姓名" onclick="javascript:alert('姓名:'+form1.textfield.value+'\n密码:'+form1.textfield2.value);"/> </p> </form> </body> </html>