javascript如何使CSS的样式改变?
我想把div的样式由colorchang2变成colorchange1如何做,主要是如何访问到colorchange1,并将它的样式赋给某一对象。<!DOCTYPEhtm...
我想把div的样式由colorchang2变成colorchange1如何做,主要是如何访问到colorchange1,并将它的样式赋给某一对象。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
#colorchange1{
background-color:#999933;
width:600px;
height:200px;
border:thick;
border-style:outset;
font-size:50px;
}
#colorchange2{
background-color:#000000;
color:#FFFFFF;
width:400px;
height:100px;
border:thin;
border-style:inset;
font-size:30px;
}
</style>
<script type="text/javascript">
function ChangeColor()
{
var oDiv = document.getElementById("colorchange1").style;
var oChange = document.getElementById("colorchange2").style;
oChange = oDiv;
}
</script>
</head>
<body onclick="ChangeColor()">
<div id="colorchange2">Click on this document!</div>
</body>
</html>
可不可以说说一下id和class的原理,如何学习才可以正确掌握 展开
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
#colorchange1{
background-color:#999933;
width:600px;
height:200px;
border:thick;
border-style:outset;
font-size:50px;
}
#colorchange2{
background-color:#000000;
color:#FFFFFF;
width:400px;
height:100px;
border:thin;
border-style:inset;
font-size:30px;
}
</style>
<script type="text/javascript">
function ChangeColor()
{
var oDiv = document.getElementById("colorchange1").style;
var oChange = document.getElementById("colorchange2").style;
oChange = oDiv;
}
</script>
</head>
<body onclick="ChangeColor()">
<div id="colorchange2">Click on this document!</div>
</body>
</html>
可不可以说说一下id和class的原理,如何学习才可以正确掌握 展开
2个回答
展开全部
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
.colorchange1{
background-color:#999933;
width:600px;
height:200px;
border:thick;
border-style:outset;
font-size:50px;
}
.colorchange2{
background-color:#000000;
color:#FFFFFF;
width:400px;
height:100px;
border:thin;
border-style:inset;
font-size:30px;
}
</style>
<script type="text/javascript">
function ChangeColor()
{
var oDiv = document.getElementById("show");
oDiv.className=oDiv.className=="colorchange2"?"colorchange1":"colorchange2";
}
</script>
</head>
<body onclick="ChangeColor()">
<div id="show" class="colorchange1">Click on this document!</div>
</body>
</html>
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
<style type="text/css">
.colorchange1{
background-color:#999933;
width:600px;
height:200px;
border:thick;
border-style:outset;
font-size:50px;
}
.colorchange2{
background-color:#000000;
color:#FFFFFF;
width:400px;
height:100px;
border:thin;
border-style:inset;
font-size:30px;
}
</style>
<script type="text/javascript">
function ChangeColor()
{
var oDiv = document.getElementById("show");
oDiv.className=oDiv.className=="colorchange2"?"colorchange1":"colorchange2";
}
</script>
</head>
<body onclick="ChangeColor()">
<div id="show" class="colorchange1">Click on this document!</div>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询