此处可参阅:。 http://jsfiddle.net/xHcPU/。
//elem.childNodes is a NodeList containing all child nodes of the array
//This includes every node - text and elements
// https://developer.mozilla.org/En/DOM/Node.childNodes
var childNodes = document.getElementById( special ).childNodes;
//arr.reduce receives an array-like object and a callback
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Array/Reduce
//We use func.call to call arr.reduce with the childNodes as the this variable
// https://developer.mozilla.org/en/JavaScript/Reference/Global_Objects/Function/call
var out = [].reduce.call( childNodes, function ( ret, child ) {
//if a node s nodeType is 3, you can safely say it s a text node
// https://developer.mozilla.org/en/nodeType
if ( child.nodeType === 3 ) {
ret += child.nodeValue.trim();
}
//if it s any other node, we just ignore it
return ret;
}, );
//out will now contain the string you seek
请注意,此处使用的2个ES5功能,Array.prototype.reduce
和String.prototype.trim
,可以很容易地由下列人员取代:shim、您本人的履行,或如果有的话,则由j Query等值取代。 我不记得<条码>减去<>编码>等值,但我确实认为存在<条码>。