当前位置: 移动技术网 > IT编程>开发语言>JavaScript > 通过javascript修改class名字-学习笔记

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

2019年04月24日  | 移动技术网IT编程  | 我要评论
<!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>

如对本文有疑问, 点击进行留言回复!!

相关文章:

验证码:
移动技术网