马上注册,结交更多好友,享用更多功能^_^
您需要 登录 才可以下载或查看,没有账号?立即注册
x
我通过js修改了div的id属性,但是虽然id确实被改变了,样式却没有改变,这是为什么?
CSS#thisfloor{
position:fixed;
left:50px;
top:500px;
width:80px;
height:300px;
background-color:dimgray;
}
#thatfloor {
position: fixed;
left: 200px;
top: 500px;
width: 80px;
height: 300px;
background-color: red;
}
HTML<div id="youxiye"> <!--界面-->
<div id="kid"></div> <!--角色-->
<div id="thisfloor" onclick="creatFloor()"></div> <!--此次地块-->
<div id="thatfloor"></div> <!--下次地块-->
</div>
js // 生成此次地块和下次地块
var thisfloor = document.getElementById("thisfloor")
var thatfloor = document.getElementById("thatfloor")
var numbers = 1;
function creatFloor() {
numbers++;
if (numbers % 2 == 0) {
thisfloor.id = "thatfloor"
thatfloor.id = "thisfloor"
}
else {
thisfloor.id = "thisfloor"
thatfloor.id = "thatfloor"
}
console.log(thisfloor.id)
}
|