您的位置:首页 > Web前端 > JQuery

jquery text()

2013-12-16 13:36 281 查看
jquery text()

.text()

This method does not accept any arguments.

Unlike the .html() method, .text() can be used in both XML and HTML documents. The result of the .text() method is a string containing the combined text of all matched elements. (Due to variations in the HTML parsers in different browsers, the text returned
may vary in newlines and other white space.)

.text()获取标签里的文本内容,.html()会连同标签一起获取

The .text() method cannot be used on form inputs or scripts. To set or get the text value of input or textarea elements, use the .val() method. To get the value of a script element, use the .html() method.

As of jQuery 1.4, the .text() method returns the value of text and CDATA nodes as well as element nodes.

.text( textString )

Description: Set the content of each element in the set of matched elements to the specified text.

textString

Type: String

A string of text to set as the content of each matched element.

.text( function(index, text) )

function(index, text)

Type: Function()

A function returning the text content to set. Receives the index position of the element in the set and the old text value as arguments.

Unlike the .html() method, .text() can be used in both XML and HTML documents.

We need to be aware that this method escapes the string provided as necessary so that it will render correctly in HTML. To do so, it calls the DOM method .createTextNode(), does not interpret the string as HTML.
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: