<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>js来改变一下样式</title>
<style type="text/css">
.box{width: 100px;height: 100px;background: red;margin-bottom:20px ;}
.boxx{border: 1px solid blue;width: 100px;height: 100px; }
.boxxr{border: 1px solid blue;width: 300px;height: 300px; }
</style>
</head>
<body>
<div class="box"></div>
<input type="button" value="加框" onclick="bs(this)">
<input type="button" value="替换" onclick="th(this)">
<script type="text/javascript">
var box=document.getElementsByClassName('box')[0]
// var box1=document.getElementsByTagName('div')[0]
function bs(num) {
box.className +=" boxx" //注意boxx前面要加空格
}
function th(num) {
box.className ="boxxr"
}
</script>
</body>
</html>点击 "运行实例" 按钮查看在线实例
Copyright 2014-2025 https://www.php.cn/ All Rights Reserved | php.cn | 湘ICP备2023035733号