text(val)方法设置所有匹配元素的文本内容。此方法类似于html(val),但转义所有HTML实体。
selector.text( val )
这是此方法使用的所有参数的描述-
val - 任何字符串
以下示例将在第二个段落中设置第一个段落的HTML内容,但是它会转义所有HTML标签。
链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/attr-text-val.html
来源:LearnFk无涯教程网
<html> <head> <title>The Selecter Example</title> <script type="text/javascript" src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.3/jquery.min.js"> </script> <script type="text/javascript" language="javascript"> $(document).ready(function() { var content=$("p#pid1").html(); $("#pid2").text(content); }); </script> <style> .red { color:red; } .green { color:green; } </style> </head> <body> <p class="green" id="pid1">This is <i>first paragraph</i>.</p> <p class="red" id="pid2">This is second paragraph.</p> </body> </html>
这将产生以下输出-
This is first paragraph.
This is <i>first paragraph</i>.
这一章《jQuery - 属性 - text( val )方法 函数》你学到了什么?在下面做个笔记吧!做站不易,你的分享是对我们最大的支持
将打开/关闭图标添加到 Twitter Bootstrap 可折叠项(手风琴)