js的onload实现:
<!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>js的onload方法的使用</title>
<script type="text/javascript">
window.onload=function(){
var myLinks = document.getElementsByTagName("a");
for(var i=0 ; i<myLinks.length; i++){
myLinks[i].onclick=function(){
alert("链接了");
}
}
}
</script>
</head>
<body>
<h1>js的onload方法的使用</h1>
<a href="#">链接1</a><br/>
<a href="#">链接2</a><br/>
<a href="#">链接3</a><br/>
<a href="#">链接4</a><br/>
<a href="#">链接5</a><br/>
<a href="#">链接6</a><br/>
</body>
</html>
jquery的ready方法的实现:
<!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>ready方法的使用2</title>
<script type="text/javascript" src="jquery-core/jquery-1.8.0.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$("a").click(function(){
alert("链接了!");
});
});
</script>
</head>
<body>
<h1>ready方法的使用2</h1>
<a href="#">链接1</a><br/>
<a href="#">链接2</a><br/>
<a href="#">链接3</a><br/>
<a href="#">链接4</a><br/>
<a href="#">链接5</a><br/>
<a href="#">链接6</a><br/>
</body>
</html>