JavaScriptは発泡事件を阻止します.
7010 ワード
<html>
<head>
<script type="text/JavaScript">
sc={
init:function(){
if(!document.getElementById||!document.createTextNode)
return ;
sc.head=document.getElementsByTagName("li")[0];
if(!sc.head)return ;
sc.myAddListener("click",sc.hEvent,"h3");
sc.myAddListener("click",sc.pEvent,"p");
sc.myAddListener("click",sc.aEvent,"a");
},
myAddListener:function(event,func,ele){
var temp=sc.head.getElementsByTagName(ele);
for(var i=0;i<temp.length;++i){
temp[i].addEventListener(event,func,false);
}
},
hEvent:function(e){
alert("h3 is being clicked");
e.stopPropagation();
e.preventDefault();
}
pEvent:function(e){
alert("p is being clicked");
e.stopPropagation();
e.preventDefault();
}
aEvent:function(e){
alert("a is being clicked");
e.stopPropagation();
e.preventDefault();
}
}
</script>
</head>
<body>
<ul>
<li>
<h3><a href="#">News Title</a></h3>
<p>Content</p>
<p><a href="#">More Detail</a></p>
</li>
</ul>
</body>
</html>