码迷,mamicode.com
首页 > Web开发 > 详细

jQuery 项目常用函数

时间:2020-07-14 01:04:58      阅读:89      评论:0      收藏:0      [点我收藏+]

标签:amp   ima   tle   head   运行   color   mamicode   example   tor   

jQuery html() 方法

定义和用法

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

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

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

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

语法

返回内容:

$(selector).html()

设置内容:

$(selector).html(content)

使用函数设置内容:

$(selector).html(function(index,currentcontent))
技术图片

 

 

实例

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
    $("button").click(function(){
        $("p").html("Hello <b>world!</b>");
    });
});
</script>
</head>
<body>

<button>修改所有P元素的内容</button>
<p>这是一个段落。</p>
<p>这是另一个段落。</p>

</body>
</html>

运行结果

技术图片

 

 点击以上按钮(修改所有p元素的内容),结果为

技术图片

 

 更多课参考jquery官网 https://jquery.com/

 

jQuery 项目常用函数

标签:amp   ima   tle   head   运行   color   mamicode   example   tor   

原文地址:https://www.cnblogs.com/wangjincai/p/13296662.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!