jquery去除css样式的方法:1、使用attr()或css()方法将css属性值设置为空来去除单个css样式;2、使用removeAttr()方法从被选元素中移除属性;3、使用removeClass()方法从被选元素中移除属性。

相关推荐:《jQuery视频教程》
jquery去除css样式
1、使用attr()方法或css()去除单个css样式
attr() 方法可以设置被选元素的属性和值,可以为匹配元素设置一个或多个属性/值对。
立即学习“前端免费学习笔记(深入)”;
想要使用attr()去除css样式,则可以为设置属性值为空即可。
例:
$("#show").attr("style","");css() 方法可以设置被选元素的一个或多个样式属性。
想要使用css()去除css样式,则可以为设置属性值为空即可。
例:
$("#show").css("style","");2、使用removeAttr()方法去除css样式
removeAttr() 方法从被选元素移除一个或多个属性。
语法
$(selector).removeAttr(attribute)
例:
$("#tab1").removeAttr("style","");3、使用removeClass()方法去除css样式
removeClass() 方法从被选元素移除一个或多个类。
注释:如果没有规定参数,则该方法将从被选元素中删除所有类。
例:从所有的 <p> 元素移除 "intro" 类:
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<script src="https://cdn.staticfile.org/jquery/1.10.2/jquery.min.js">
</script>
<script>
$(document).ready(function(){
$("button").click(function(){
$("p").removeClass("intro");
});
});
</script>
<style type="text/css">
.intro{
font-size:120%;
color:red;
}
</style>
</head>
<body>
<h1>这是一个标题</h1>
<p class="intro">这是一个段落。</p>
<p class="intro">这是另一个段落。</p>
<button>移除所有P元素的"intro"类</button>
</body>
</html>更多编程相关知识,请访问:编程视频课程!!
以上就是jquery怎么去除css样式?的详细内容,更多请关注php中文网其它相关文章!
每个人都需要一台速度更快、更稳定的 PC。随着时间的推移,垃圾文件、旧注册表数据和不必要的后台进程会占用资源并降低性能。幸运的是,许多工具可以让 Windows 保持平稳运行。
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号