顯示不了呢
?<form>
? <!--當(dāng)點(diǎn)擊相應(yīng)按鈕,執(zhí)行相應(yīng)操作,為按鈕添加相應(yīng)事件-->
? ? <input type="button" value="改變顏色" onclick="changecolor()" > ?
? ? <input type="button" value="改變寬高" onclick="changewidth()" >
? ? <input type="button" value="隱藏內(nèi)容" onclick="changehide()" >
? ? <input type="button" value="顯示內(nèi)容" onclick="changeshow()">
? ? <input type="button" value="取消設(shè)置" onclick="offset()">
? </form>
? <script type="text/javascript">
? var obj=document.getElementById("txt");
//定義"改變顏色"的函數(shù)
function changecolor(){
? ? //var obj=document.getElementById("txt");
? ? obj.style.color="red";
? ? obj.style.background="#CCC";
}
//定義"改變寬高"的函數(shù)
function changewidth(){
? ? //var obj=document.getElementById("txt");
? ? obj.style.width="200px";
? ? ?obj.style.height="200px";
}
//定義"隱藏內(nèi)容"的函數(shù)
function changehide(){
? ? //var obj=document.getElementById("txt");
? ? obj.style.disply="none";
}
//定義"顯示內(nèi)容"的函數(shù)
function changeshow(){
? ? //var obj=document.getElementById("txt");
? ? obj.style.disply="block";
}
//定義"取消設(shè)置"的函數(shù)
function offset(){
? ? //var obj=document.getElementById("txt");
? ? var message=confirm("確認(rèn)要取消設(shè)置嗎");
? ? if(message==true){
? ? obj.removeAttribute('style');}
}
? </script>
2019-03-05
隱藏/顯示內(nèi)容的那兩個函數(shù),obj.style.display,display這個地方單詞拼錯了。然后整體代碼運(yùn)行不了是因?yàn)槟阕詈笠欢文莻€取消設(shè)置的函數(shù)里面有個地方的符號是中文,你把那段代碼復(fù)制到控制臺試試就曉得了,會顯示invaid token的,我復(fù)制進(jìn)去試了下,是因?yàn)関ar message=confirm("確認(rèn)要取消設(shè)置嗎");這個地方末尾分號你是在中文輸入法下打出來的,導(dǎo)致后面都運(yùn)行不了。你仔細(xì)對比下其他地方的分號就能看出來了
2019-03-05
? var message=confirm("確認(rèn)要取消設(shè)置嗎");你這個分號是中文的分號
你的display拼錯了
2019-02-28
你這個應(yīng)該是那個全局變量的問題,方法外面的那個obj不能載函數(shù)里面用吧
2019-02-28
2019-02-28
什么顯示不了?