删除空白节点

function removeWhitespace(element){
var loopIndex;
for (loopIndex = 0; loopIndex < element.childNodes.length; loopIndex++) {
var currentNode = element.childNodes[loopIndex];
if (currentNode.nodeType == 1) {
removeWhitespace(currentNode);
}
if (((/^\s+$/.test(currentNode.nodeValue))) && (currentNode.nodeType = 3)) {
element.removeChild(element.childNodes[loopIndex--]);
}
}
}

你可能感兴趣的:(删除)