jQuery 中的 text( val )方法函数

首页 / jQuery入门教程 / jQuery 中的 text( val )方法函数

text(val)方法获取所有匹配元素的组合文本内容。

text( val ) - 语法

selector.text( val )

这是此方法使用的所有参数的描述-

  • val    -  这是要设置的文本值。

text( val ) - 示例

以下是一个简单的示例,简单说明了此方法的用法-

无涯教程网

<html>
   <head>
      <title>The jQuery 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() {
            $("div").click(function () {
               $(this).text( "<h1>Click another square</h1>");
            });
         });
      </script>
		
      <style>
         .div{ margin:10px;padding:12px; border:2px solid #666; width:60px;}
      </style>
   </head>
	
   <body>
      <p>Click on any square below to see the result:</p>
		
      <div class="div" style="background-color:blue;"></div>
      <div class="div" style="background-color:green;"></div>
      <div class="div" style="background-color:red;"></div>
   </body>
</html>

这将产生以下输出-

祝学习愉快!(内容编辑有误?请选中要编辑内容 -> 右键 -> 修改 -> 提交!)

技术教程推荐

黄勇的OKR实战笔记 -〔黄勇〕

ZooKeeper实战与源码剖析 -〔么敬国〕

接口测试入门课 -〔陈磊〕

编译原理实战课 -〔宫文学〕

乔新亮的CTO成长复盘 -〔乔新亮〕

高楼的性能工程实战课 -〔高楼〕

快速上手C++数据结构与算法 -〔王健伟〕

结构思考力 · 透过结构看问题解决 -〔李忠秋〕

工程师个人发展指南 -〔李云〕

好记忆不如烂笔头。留下您的足迹吧 :)