许愿瓶里的小怪兽
2017-11-16 09:05
<html>
<head><title>classname属性</title>
<style type="text/css">
input{
font-size:10px;
}
.one{
width:200px;
background-color:#CCC;
}
.two{
font-size:18px;
color:#FOO;
}
</style>
</head>
<body>
<h1 id="con" class="one">Javascript</h1>
<form>
<input type="button" value="点击更改" onclick="modifyclass()">
</form>
<script type="text/javascript">
var mystr=getelementbyid("con");
document.write("p元素的class值为:"+mystr.classname);
function modifyclass(){
mystr.classname=two;
}
</script>
</body>
</html>
var mystr=getelementbyid("con"); 应该是var mychar=document.getElementById("con");
document.write("p元素的class值为:"+mystr.classname);和mystr.classname中classname应该是className
mystr.classname=two; 应该是mychar.className="two";
mystr.classname = "two"
className中“N”大写, mystr.classname=“two”;等号后面的内容没有引号
JavaScript入门篇
740081 学习 · 9566 问题
相似问题