<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8" /> <title>New Web Project</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()"> <p><a href="#">链接1</a></p> <p><a href="#">链接2</a></p> </body> </html>