我查看了函数的jQuery
源代码:.empty()
empty: function() {
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
// Remove element nodes and prevent memory leaks
if ( elem.nodeType === 1 ) {
jQuery.cleanData( elem.getElementsByTagName("*") );
}
// Remove any remaining nodes
while ( elem.firstChild ) {
elem.removeChild( elem.firstChild );
}
}
innerHTML
仅将 更改为空字符串就不能简单得多:
empty: function() {
for ( var i = 0, elem; (elem = this[i]) != null; i++ ) {
elem.innerHTML = "";
}
empty
文档:_
描述:从 DOM 中删除匹配元素集的所有子节点。