jQuery 中的 html( val )方法函数

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

html(val)方法设置每个匹配元素的html内容。此属性在XML文档上不可用。

html( val ) - 语法

selector.html( val )

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

  • val   -  这是要设置的html内容。

html( 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).html( "<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>

这将产生以下输出-

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

技术教程推荐

AI技术内参 -〔洪亮劼〕

全栈工程师修炼指南 -〔熊燚(四火)〕

移动端自动化测试实战 -〔思寒〕

MongoDB高手课 -〔唐建法(TJ)〕

现代C++编程实战 -〔吴咏炜〕

跟着高手学复盘 -〔张鹏〕

去无方向的信 -〔小麥〕

中间件核心技术与实战 -〔丁威〕

PPT设计进阶 · 从基础操作到高级创意 -〔李金宝(Bobbie)〕

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