添加动态事件

===
<style>
.dn{background:red;color:white;text-decoration:underline;font-weight:bold}
.up{background:green;color:yellow;}
</style>
<p>aaaaaaaa</p>
<p>bbbbbbbb</p>
<p>cccccccc</p>
<p>ddddddddd</p>
<script>
o=document.all.tags("p");
for(i=0;i<o.length;i++){
o[i].onclick=function(){set(this)}
o[i].className='up';
}

function set(obj){
for(i=0;i<o.length;i++)
o[i].className='up';
obj.className='dn';
alert(obj.innerText);
}
</script>

 
原文地址:https://www.cnblogs.com/chenzhao/p/2082126.html