样式改变了,但mychar.className输出还是one,没有变化!触发onclick事件后不是应该输出的是two了嘛!
<style> .one{ color: #000; } .two{ color: red; } </style> </head> <body> <p id="con" class="one">这是一个p标签</p> <form action=""> <input type="button" value="点击更改" onclick="monifyclass()"> </form> <script> var mychar=document.getElementById("con"); document.write("p元素的class值为"+mychar.className+"<br>"); function monifyclass(){ mychar.className="two"; } console.log(mychar.className); </script>