小编Ume*_*ena的帖子

如何仅使用javascript切换/切换div的类

我希望a div切换其类(切换)onclick,然后再次恢复原始类onclick

我的代码是:

 function myfunc() {
    //the code over here
 }
Run Code Online (Sandbox Code Playgroud)
.normal { 
  width:25%;
  height:25%;
  background: #f00;
}

.active { 
  width:100%;
  height:100%;
  background: #f00;
}

#div{}
Run Code Online (Sandbox Code Playgroud)
<body>
  <div id="div" onclick="myfunc()">click here</div>
</body>
Run Code Online (Sandbox Code Playgroud)

html javascript class onclick toggle

3
推荐指数
1
解决办法
4万
查看次数

标签 统计

class ×1

html ×1

javascript ×1

onclick ×1

toggle ×1