连续点击按钮,p内文字style会切换,但最后显示文字时,one和two不会切换,为什么?怎么写才对?
<!DOCTYPE html> <html> <head> <meta charset="utf-8"/> <title>changeClass</title> <style> .one { font-size:20px; color:#A0A; background-color:#FA0; } .two { font-size:50px; color:#000; background-color:#00F; } input { font-size:50px; } </style> </head> <body> <form> <input type="button" value="change_class_button" onclick="onChangeClass()"/> </form> <p id="testID" class="one">Javascript abc 汉字</p> <script> var some=document.getElementById("testID"); document.write("元素p的class值为"+some.className); function onChangeClass() { if(some.className == "one") { some.className="two"; } else { some.className="one"; } } </script> </body> </html>
连续点击按钮,p内文字style会切换,但最后显示文字时,one和two不会切换,为什么?怎么写才对?