视频链接视频
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>事件的委派</title>
<style type="text/css">
#u1{
background-color: #6495ED;
}
</style>
<script type="text/javascript">
window.onload=function(){
var btn01=document.getElementById("btn01");
var u1=document.getElementById("u1");
btn01.onclick=function(){
var li=document.createElement("li");
li.innerHTML="<a href='javascript:;' class='link'>超链接</a>";
u1.appendChild(li);
}
var allA=document.getElementsByTagName("a");
u1.onclick=function(event){
event=event||window.event;
if(event.target.className=="link"){
alert("我是ul的单击响应函数");
}
}
}
</script>
</head>
<body>
<button id="btn01">按钮1:点击按钮添加超链接</button>
<ul id="u1">
<li><a href="javascript:;" class="link">超链接</a></li>
<li><a href="javascript:;" class="link">超链接</a></li>
<li><a href="javascript:;" class="link">超链接</a></li>
<li><a href="javascript:;" class="link">超链接</a></li>
</ul>
</body>
</html>
|