"innerText" & "innerHTML" & "textContent" & "nodeValue"差異?

比較"innerText" & "textContent":

這篇連結(http://stackoverflow.com/questions/34283414/difference-between-tolocalelowercase-and-tolowercase)擷取重點如下:

--> innerText is non-standard, and will not work across all browsers.

--> Use textContent instead, and only add innerText to support old versions of IE.


比較"textContent" & "nodeValue" &  "innerHTML":

HTML DOM textContent Property:
http://www.w3schools.com/jsref/prop_node_textcontent.asp

擷取重點如下:

--> sets or returns the textual content of the specified node, and all its descendants.

--> If you set the textContent property, any child nodes are removed and replaced by a single Text node containing the specified string.

-->  Sometimes this property can be used instead of the nodeValue property, but remember that this property returns the text of all child nodes as well.

--> To set or return the HTML content of an element, use the innerHTML property.


比較"textContent" & "nodeValue":

HTML DOM nodeValue Property:
http://www.w3schools.com/jsref/prop_node_nodevalue.asp

擷取重點如下:

--> sets or returns the node value of the specified node.

--> If the node is an element node, the nodeValue property will return null.

--> If you want to return the text of an element, remember that text is always inside a Text node, and you will have to return the Text node's node value (element.childNodes[0].nodeValue).

--> For other node types, the nodeValue property will return different values for different node types.

--> An alternative to the nodeValue property can be the textContent property.



留言

熱門文章