现在自学JavaScript,发现无法用JS改变ID里面的className的属性,求大神教教我! 10
现在自学JavaScript,发现无法用JS改变ID里面的className的属性,求大神教教我!<!DOCTYPEhtml><htmllang="zh-cn"><hea...
现在自学JavaScript,发现无法用JS改变ID里面的className的属性,求大神教教我!<!DOCTYPE html>
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type">
<meta content="text/html; charset=utf-8">
<meta charset="utf-8">
<style type="text/css" media="screen">
#cs{ background-color: #f00; width: 300px; height: 200px; }
.ts{ background-color: #6a0; width: 150px; height: 150px; }
</style>
</head>
<body>
<div id="cs">
<div class="ts">你好</div>
</div>
<script>
document.getElementById("cs"),document.getElementsByClassName('ts').style.backgroundColor="#ff0";
</script>
</body>
</html> 展开
<html lang="zh-cn">
<head>
<meta http-equiv="Content-Type">
<meta content="text/html; charset=utf-8">
<meta charset="utf-8">
<style type="text/css" media="screen">
#cs{ background-color: #f00; width: 300px; height: 200px; }
.ts{ background-color: #6a0; width: 150px; height: 150px; }
</style>
</head>
<body>
<div id="cs">
<div class="ts">你好</div>
</div>
<script>
document.getElementById("cs"),document.getElementsByClassName('ts').style.backgroundColor="#ff0";
</script>
</body>
</html> 展开
2个回答
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询