2. text()方法

2. text()方法 


此方法类似于JavaScript中的innerText属性,可以用来读取或者设置某个元素中的文本内容。

继续使用以上的HTML代码 


node2:/var/www/html/jquery#cat t35.html 
<p title="选择你最喜欢的水果."><strong>你最喜欢的水果的是?</strong></p>
<script type="text/javascript" src="jquery-2.2.2.min.js"></script>    
<script type="text/javascript" src="t35.js"></script>

node2:/var/www/html/jquery#cat t35.js
var p_html = $("p").text(); //获取<p>元素的HTML代码
console.log(p_html);
alert(p_html);

猜你喜欢

转载自blog.csdn.net/zhaoyangjian724/article/details/89884264