方法:1、用attr()将class属性的值设为空,语法“$(selector).attr("class","")”;2、用removeAttr()移除class属性,语法“$(selector).removeAttr("class")”。

本教程操作环境:windows7系统、jquery1.10.2版本、Dell G3电脑。
jquery去除class属性有两种方法:
-
使用attr()将元素中class属性的值设为空
语法:
$(selector).attr("class","") -
使用removeAttr()移除元素中的class属性
jQuery 1.12.4下载jQuery 1.12.4是jQuery 1.x系列的最后一个正式稳定版本,由jQuery团队于2016年发布。该版本主要面向需要兼容旧版浏览器环境的网站和Web应用,尤其适用于仍需支持Internet Explorer 6、Internet Explorer 7、Internet Explorer 8等老旧浏览器的项目。
语法:
$(selector).removeAttr("class")
示例:
html>
<meta><script></script><script>
$(document).ready(function() {
$("button").click(function() {
$(".box1").attr("class", "");
$(".box2").removeAttr("class");
});
});
</script><style>
div {
border: 1px solid red;
margin: 10px;
}
.box1 {
background-color: #FFC0CB;
}
.box2 {
background-color: green;
color: white;
}
</style><div>测试文本</div>
<div>测试文本</div>
<br><button>去掉class属性</button>

相关视频教程推荐:jQuery视频教程










