樣式改變了,但mychar.className輸出還是one,沒(méi)有變化!觸發(fā)onclick事件后不是應(yīng)該輸出的是two了嘛!
<style> ????????.one{ ????????????color:?#000; ????????} ????????.two{ ????????????color:?red; ????????} ????</style> </head> <body> <p?id="con"?class="one">這是一個(gè)p標(biāo)簽</p> <form?action=""> ????<input?type="button"?value="點(diǎn)擊更改"?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)是即使沒(méi)有鼠標(biāo)點(diǎn)擊響應(yīng)事件也會(huì)執(zhí)行的,估計(jì)就是因?yàn)槭髽?biāo)點(diǎn)擊了此函數(shù)也沒(méi)有相應(yīng)的更新
你可以在function monifyclass()函數(shù)定義里加一句console.log(mychar.className),隨著鼠標(biāo)點(diǎn)擊響應(yīng)此函數(shù)后,就會(huì)有期待的結(jié)果了。
2018-08-18
html是結(jié)構(gòu),相當(dāng)于骨架;
css是樣式;美化頁(yè)面格式的;
js是交互;豐富頁(yè)面內(nèi)容的!
2018-07-23
那把 console.log(myChar.className); 放到 function()里面
2018-07-22
var mychar = document.getElementById("con");
這句應(yīng)該放到 function ()里面
2018-07-22
還沒(méi)學(xué)到console.log ,我是老實(shí)按照基礎(chǔ)的方法進(jìn)行的
2018-07-20
console.log(mychar.className)是即使沒(méi)有鼠標(biāo)點(diǎn)擊響應(yīng)事件也會(huì)執(zhí)行的,估計(jì)就是因?yàn)槭髽?biāo)點(diǎn)擊了此函數(shù)也沒(méi)有相應(yīng)的更新
你可以在function monifyclass()函數(shù)定義里加一句console.log(mychar.className),隨著鼠標(biāo)點(diǎn)擊響應(yīng)此函數(shù)后,就會(huì)有期待的結(jié)果了。