function countChars(elm) {
if (elm.nodeType == 3) { // TEXT_NODE
return elm.nodeValue.length;
}
var count = 0;
for (var i = 0, child; child = elm.childNodes[i]; i++) {
count += countChars(child);
}
return count;
}
我想通過這個函數的字符串像countChars("hello")
;但那不起作用。什麼是我可以傳遞的元素的例子?這個函數需要什麼樣的參數?
1爲分銷商從特定的*元素節點*中拋出一個通用的* DOM節點*。 – 2012-01-31 20:29:57
+1在此1分鐘內最準確和最具說明性。 :-) – JimmiTh 2012-01-31 20:33:32