jQuery html() 方法

jQuery 教程 · 2019-03-27 13:57:56

实例

改变所有 <p> 元素的内容:

$("button").click(function(){ $("p").html("Hello <b>world</b>!"); });

定义和用法

html() 方法设置或返回被选元素的内容(innerHTML)。

当该方法用于返回内容时,则返回第一个匹配元素的内容。

当该方法用于设置内容时,则重写所有匹配元素的内容。

提示:如只需设置或返回被选元素的文本内容,请使用 text() 方法。

语法

返回内容:

  
    $(selector).html()
  

设置内容:

  
    $(selector).html(content)
  

使用函数设置内容:

  
    $(selector).html(function(index,currentcontent))
  

参数 描述
content 必需。规定被选元素的新内容(可包含 HTML 标签)。
function(index,currentcontent) 可选。规定返回被选元素的新内容的函数。
  • index - 返回集合中元素的 index 位置。
  • currentcontent - 返回被选元素的当前 HTML 内容。

点击查看所有 jQuery 教程 文章: https://www.codercto.com/courses/l/35.html

查看所有标签

A Byte of Python

A Byte of Python

Swaroop C H / Lulu Marketplace / 2008-10-1 / USD 27.98

'A Byte of Python' is a book on programming using the Python language. It serves as a tutorial or guide to the Python language for a beginner audience. If all you know about computers is how to save t......一起来看看 《A Byte of Python》 这本书的介绍吧!

Markdown 在线编辑器
Markdown 在线编辑器

Markdown 在线编辑器

HEX HSV 转换工具
HEX HSV 转换工具

HEX HSV 互换工具