jQuery 中的 html( )方法函数

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

html()方法获取第一个匹配元素的html内容。此属性在XML文档上不可用,但适用于XHTML文档。

html( ) - 语法

selector.html()

html( ) - 示例

以下示例将获取第一段的HTML内容,并将其显示在第二段中。请同时检查 html(val)方法的描述。

<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").html();
            $("#pid2").html( content );
         });
      </script>
		
      <style>
         .red { color:red; }
         .green { color:green; }
      </style>
   </head>
	
   <body>
      <p class="green" id="pid1">This is first paragraph.</p>
      <p class="red" id="pid2">This is second paragraph.</p>
   </body>
</html>

这将产生以下输出-

链接:https://www.learnfk.comhttps://www.learnfk.com/jquery/attr-html.html

来源:LearnFk无涯教程网

This is first paragraph.

This is first paragraph.

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

技术教程推荐

技术管理实战36讲 -〔刘建国〕

代码精进之路 -〔范学雷〕

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

NLP实战高手课 -〔王然〕

Django快速开发实战 -〔吕召刚〕

手把手教你玩音乐 -〔邓柯〕

etcd实战课 -〔唐聪〕

操作系统实战45讲 -〔彭东〕

Midjourney入门实践课 -〔Jovi〕

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