純JavaScript,我需要刪除li
上點擊span
。javascript刪除div onclick
- 通過點擊
remove
我想刪除它的div。
Object.prototype.remove = function(){
this.parentNode.removeChild(this);
};
var lis = document.querySelectorAll('li');
var button = document.querySelectorAll('span');
for (var i = 0, len = lis.length; i < len; i++) {
button[i].addEventListener('click', remove, false);
}
<ul>
<li>List item one<span> remove</span></li>
<li>List item two<span> remove</span></li>
<li>List item three<span> remove</span></li>
<li>List item four<span> remove</span></li>
<li>List item five<span> remove</span></li>
<li>List item six<span> remove</span></li>
</ul>
你想刪除其格? –