通过javascript修改class名字-学习笔记 - Go语言中文社区

通过javascript修改class名字-学习笔记


<!doctype html>
<html>
<head>
<meta charset="urtf-8">
<title>通过js改变class名字改变样式</title>
<style>
.tao { /*初始样式*/
border-radius:35px;
width:100px;
height:100px;
border:1px solid #f00;
text-align:center;
line-height:100px;
}
.taot{ /*class名字为taot的样式*/
width:100px;
height:100px;
border-radius:50px;
border:1px solid #008cba;
text-align:center;
line-height:100px;

}
</style>
<script>
</script>
</head>

<body>
<div class="tao">
圆形DIV
</div>
<input type="button" value="变圆" id="shi" onclick="fn()">
<script>
//获取对象
let tao=document.getElementsByClassName("tao")[0];//通过class获取名字注意添加后面[0];
function fn(){
tao.className="taot"
}
</script>
</body>
</html>
版权声明:本文来源博客园,感谢博主原创文章,遵循 CC 4.0 by-sa 版权协议,转载请附上原文出处链接和本声明。
原文链接:https://www.cnblogs.com/TSGing/p/10757966.html
站方申明:本站部分内容来自社区用户分享,若涉及侵权,请联系站方删除。
  • 发表于 2019-11-17 16:36:10
  • 阅读 ( 1111 )
  • 分类:

0 条评论

请先 登录 后评论

官方社群

GO教程

猜你喜欢