樣式改變了,但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>
2018-07-20
console.log(mychar.className)是即使沒有鼠標點擊響應事件也會執行的,估計就是因為鼠標點擊了此函數也沒有相應的更新
你可以在function monifyclass()函數定義里加一句console.log(mychar.className),隨著鼠標點擊響應此函數后,就會有期待的結果了。
2018-08-18
html是結構,相當于骨架;
css是樣式;美化頁面格式的;
js是交互;豐富頁面內容的!
2018-07-23
那把 console.log(myChar.className); 放到 function()里面
2018-07-22
var mychar = document.getElementById("con");
這句應該放到 function ()里面
2018-07-22
還沒學到console.log ,我是老實按照基礎的方法進行的
2018-07-20
console.log(mychar.className)是即使沒有鼠標點擊響應事件也會執行的,估計就是因為鼠標點擊了此函數也沒有相應的更新
你可以在function monifyclass()函數定義里加一句console.log(mychar.className),隨著鼠標點擊響應此函數后,就會有期待的結果了。