本文实例讲述了jquery给多个不同元素添加class样式的方法。分享给大家供大家参考。具体分析如下:
jQuery可以通过addClass()方法给多个不同的html元素同时添加相同的class
<!DOCTYPE html>
<html>
<head>
<script src="js/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("h1,h2,p").addClass("blue");
$("div").addClass("important");
});
});
</script>
<style type="text/css">
.important
{
font-weight:bold;
font-size:xx-large;
}
.blue
{
color:blue;
}
</style>
</head>
<body>
<h1>Heading 1</h1>
<h2>Heading 2</h2>
<p>This is a paragraph.</p>
<p>This is another paragraph.</p>
<div class="aritcle_card">
<a class="aritcle_card_img" href="/xiazai/code/5836">
<img src="https://img.php.cn/upload/webcode/000/120/096/5d885b89678f3930.jpg" alt="Gridster.js多列网格式拖动布局插件">
</a>
<div class="aritcle_card_info">
<a href="/xiazai/code/5836">Gridster.js多列网格式拖动布局插件</a>
<p>网页中拖动 DIV 是很常见的操作,今天就分享给大家一个 jQuery 多列网格拖动布局插件,和其它的插件不太一样的地方在于你处理拖放的元素支持不同大小,并且支持多列的网格布局,它们会自动的根据位置自己排序和调整。非常适合你开发具有创意的应用。这个插件可以帮助你将任何的 HTML 元素转换为网格组件</p>
<div class="">
<img src="/static/images/card_xiazai.png" alt="Gridster.js多列网格式拖动布局插件">
<span>75</span>
</div>
</div>
<a href="/xiazai/code/5836" class="aritcle_card_btn">
<span>查看详情</span>
<img src="/static/images/cardxiayige-3.png" alt="Gridster.js多列网格式拖动布局插件">
</a>
</div>
<div>This is some important text!</div>
<br>
<button>Add classes to elements</button>
</body>
</html>希望本文所述对大家的jQuery程序设计有所帮助。
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
C++高性能并发应用_C++如何开发性能关键应用
Java AI集成Deep Java Library_Java怎么集成AI模型部署
Golang后端API开发_Golang如何高效开发后端和API
Python异步并发改进_Python异步编程有哪些新改进
C++系统编程内存管理_C++系统编程怎么与Rust竞争内存安全
Java GraalVM原生镜像构建_Java怎么用GraalVM构建高效原生镜像
Python FastAPI异步API开发_Python怎么用FastAPI构建异步API
C++现代C++20/23/26特性_现代C++有哪些新标准特性如modules和coroutines
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号