二维码防伪系统

新闻中心

各种活动实时推动

用JS添加和删除class类名

发布时间:2024-11-09 点击次数:210

今天给大家分享的建站知识是:用JS添加和删除class类名。

方法1.

添加:document.getElementById("id").classList.add("类名");

删除:document.getElementById("id").classList.remove("类名");

方法2

var classVal=document.getElementById("id").getAttribute("class");

添加:document.getElementById("id").setAttribute("class",classVal.concat(" 类名"));

删除:document.getElementById("id").getAttribute("class").replace("类名"," ");

方法3.

添加:document.getElementById("id").className+=" 类名";

copy © 2025 星澜网络 All Rights Reserved

备案号:鲁ICP备2023015769号 sitemap