請大神幫忙看看哪里有問題所有按鈕都沒反應(yīng)
? <form>
? <!--當(dāng)點擊相應(yīng)按鈕,執(zhí)行相應(yīng)操作,為按鈕添加相應(yīng)事件-->
? ? <input type="button" value="改變顏色" onclick="mycolor()"/> ?
? ? <input type="button" value="改變寬高" onclick="mysize()"/>
? ? <input type="button" value="隱藏內(nèi)容" onclick="mynone()"/>
? ? <input type="button" value="顯示內(nèi)容" onclick="myblock()"/>
? ? <input type="button" value="取消設(shè)置" onclick="mycancel()"/>
? </form>
? <script type="text/javascript">
? var mytxt=document.getElementById("txt");
//定義"改變顏色"的函數(shù)
? function mycolor()
? { mytxt.style.color="red";
? ? mytxt.style.backgroundColor="#ccc";
? }
//定義"改變寬高"的函數(shù)
? function mysize()
? { mytxt.style.width="300px";
? ? mytxt.style.height="300px";
? }
//定義"隱藏內(nèi)容"的函數(shù)
? function mynone()
? { mytxt.style.display="none";
? }
//定義"顯示內(nèi)容"的函數(shù)
? function myblock()
? { mytxt.style.display="block";
? }
//定義"取消設(shè)置"的函數(shù)
? function mycancel()
? { var cel=confirm("是否取消所有設(shè)置");
? ? if(cel==true)
? ? { mytxt.style="""";//或者 mytxt.removeAttribute("style");
? ? }
? }
? </script>
2016-07-04
//定義"取消設(shè)置"的函數(shù)
? function mycancel()
? { var cel=confirm("是否取消所有設(shè)置");
? ? if(cel==true)
? ? { mytxt.style="""";//或者 mytxt.removeAttribute("style");
? ? }
? }
在這段代碼中有兩處錯誤:
1、?{ var cel=confirm("是否取消所有設(shè)置");
這一行當(dāng)中的“分號”用成了中文格式,這個錯誤是我放在代碼編輯器中發(fā)現(xiàn)的;
2、?{ mytxt.style="""";//或者 mytxt.removeAttribute("style");?}
這一行代碼當(dāng)中mytxt.style = """";是語法錯誤,
谷歌瀏覽器中給出了以下報錯提示:
正確的書寫方式應(yīng)該是mytxt.style = "";
可以試一下谷歌瀏覽器的console功能
2016-07-04
你的是mytxt嗎?
2016-07-04
function gbys(){
??? txt.style.color="#eee";
??? txt.style.backgroundColor="#f9c";
}
//定義"改變寬高"的函數(shù)
function gbkg(){
??? txt.style.width="300px";
??? txt.style.height="500px"; ?
}
//定義"隱藏內(nèi)容"的函數(shù)
function ycnr(){
??? txt.style.display='none';
}
//定義"顯示內(nèi)容"的函數(shù)
function xsnr(){
??? txt.style.display='block';
}
//定義"取消設(shè)置"的函數(shù)
function qxsz(){
? var qxss= confirm('是否取消設(shè)置?');
? if (qxss==true) {
???? txt.removeAttribute("style");
?? }
}