摘要:如何用js控制,并改變css的樣式,顏色,長(zhǎng)寬內(nèi)容<!DOCTYPE html><html><head> <title>測(cè)試</title> <style type="text/css"> #box{width: 100px;height: 100px;background: red;margin: 30p
如何用js控制,并改變css的樣式,顏色,長(zhǎng)寬內(nèi)容
<!DOCTYPE html>
<html>
<head>
<title>測(cè)試</title>
<style type="text/css">
#box{width: 100px;height: 100px;background: red;margin: 30px,50px,20px,10px}
</style>
</head>
<body>
<div id = "box"></div>
<input type="button" value="變高" onclick="aa()">
<input type="button" value="變寬" onclick="bb()">
<input type="button" value="變色" onclick="cc()">
<input type="button" value="重置" onclick="dd()">
<input type="button" value="隱藏" onclick="ee()">
<input type="button" value="顯示" onclick="ff()">
<script type="text/javascript">
var box
window.onload= function(){
box = document.getElementById('box')
}
function aa(){
box.style.height="300px";
}
function bb(){
box.style.width="300px";
}
function cc(){
box.style.background="#000"
}
function dd(){
box.style.height="100px"
box.style.width="100px"
box.style.background="red"
}
function ee(){
box.style.display="none"
}
function ff(){
box.style.display="block"
}
</script>
</body>
</html>
批改老師:韋小寶批改時(shí)間:2018-12-13 14:58:04
老師總結(jié):寫的很不錯(cuò)!這種效果在很頁(yè)面都會(huì)有類似的!課后記得多練習(xí)哦!