javascript控制div的样式

Original 2019-01-24 15:15:58 206
abstract:<!DOCTYPE html><html lang="en"><head><meta charset="UTF-8"><meta name="viewport" content="width=device-width, initial-scale=1.0">&

<!DOCTYPE html>

<html lang="en">

<head>

<meta charset="UTF-8">

<meta name="viewport" content="width=device-width, initial-scale=1.0">

<meta http-equiv="X-UA-Compatible" content="ie=edge">

<title>Javascript控制div的样式</title>

<style>

#box{

width:100px;

height:100px;

background-color:lightblue;

}

</style>

</head>

<body>

<div id="box"></div>

<script>

document.getElementById('box').onclick = function() {

this.style.backgroundColor = 'orange';

this.style.borderRadius = '50%';

}

</script>

</body>

</html>


Correcting teacher:天蓬老师Correction time:2019-01-24 17:23:04
Teacher's summary:backgroundColor, 对于这样的复合样式, 注意语法 ,如果不想用属性方式设置, 可以用setAttribute()

Release Notes

Popular Entries