移除事件详解如何优雅地移除元素
// 移除DOM元素的方法
var elem = document.getElementById('example');
if (elem.parentNode) {
elem.parentNode.removeChild(elem);
}
// 移除数组中的元素的方法
var arr = [1, 2, 3, 4];
var index = arr.indexOf(3);
if (index > -1) {
arr.splice(index, 1);
}
// 移除字符串中的子串的方法
var str = 'hello world';
var newStr = str.replace('world', '');
下载地址
用户评论