jQuery API 返回首页目录 | jQuery API 中英文对照版
text(val)
text(val)

设置所有匹配元素的文本内容。这个函数与html()函数具有同样的效果。

返回值:String

参数:

  • val (String): 文本内容
示例:

设置所有段落的文本内容。

$("p").text("Some new text.");

HTML 代码:

<p>Test Paragraph.</p>

结果:

<p>Some new text.</p>

 
text( val )

Set the text contents of all matched elements.

Similar to html(), but escapes HTML (replace "<" and ">" with their HTML entities).

Return value: String
Parameters:

  • val (String): The text value to set the contents of the element to.

Example:

Sets the text of all paragraphs.

 $("p").text("<b>Some</b> new text.");  
Before:
 <p>Test Paragraph.</p>  
Result:
 <p><b>Some</b> new text.</p>

Example:

Sets the text of all paragraphs.

 $("p").text("<b>Some</b> new text.", true);  
Before:
 <p>Test Paragraph.</p>  
Result:
 <p><b>Some</b> new text.</p>  
相关链接
asp之家 | jQuery官方网站 | jQuery中文网 | 电子书作者网站 | 电子书作者blog