javascript怎样去掉class属性

lxf2023-03-21 09:34:01

在javascript中,可以借助setAttribute()方式来除掉class属性数值,只需要使用该函数公式将class属性数值设为空字符串就可以,词法为“原素目标.setAttribute("class","")”。

javascript怎样去掉class属性

实例教程作业环境:windows7系统软件、javascript1.8.5版、Dell G3计算机。

在javascript中,可以借助setAttribute()方式来除掉class属性数值。

setAttribute() 方式加上特定的特性,并为其赋特定数值。如果这些特定的特性已存有,则仅设定/变更值。

只需要使用setAttribute()方式将class属性数值设为空字符串就可以除掉class属性数值。

完成实例:

<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<style type="text/css">
.box{
border: 1px solid red;
background-color: pink;
}
</style>
</head>

<body>
<div id="box" class="box">检测文字</div><br>
<button onclick="myFunction()"> 清除class属性数值(除掉款式)</button>

<script type="text/javascript">
function myFunction() {
var div=document.getElementById("box");
div.setAttribute("class","");
}
</script>

</body>
</html>

javascript怎样去掉class属性

【相关信息:javascript学习教程

以上就是关于javascript怎样去掉class属性的系数的具体内容,大量欢迎关注AdminJS其他类似文章!