用事件委托的方法点击每个li让其删除

<!doctype html>
<html>
<head>
<meta charset="utf-8">
<title>无标题文档</title>
<script>
window.onload=function()
{
var oUl=document.getElementById('ul1');
oUl.onclick=function(ev)
{
var oEvent=ev||event;
var oSrc=oEvent.srcElement||oEvent.target;
if(oSrc.tagName=='LI')
{
oUl.removeChild(oSrc);
}
}
};
</script>
</head>

<body>
<ul id="ul1">
<li>1</li>
<li>2</li>
<li>3</li>
<li>4</li>
<li>5</li>
<li>6</li>
<li>7</li>
<li>8</li>
<li>9</li>
</ul>
</body>
</html>

posted on 2015-03-03 09:34  wish&will  阅读(413)  评论(0编辑  收藏  举报