今天你好
2016-06-05 11:07:15
? <form>? <!--當(dāng)點(diǎn)擊相應(yīng)按鈕,執(zhí)行相應(yīng)操作,為按鈕添加相應(yīng)事件-->? ? <input type="button" value="改變顏色" onclick="changecolor()" > ?? ? <input type="button" value="改變寬高" onclick="changewh()" >? ? <input type="button" value="隱藏內(nèi)容" onclick="hidetext()" >? ? <input type="button" value="顯示內(nèi)容" onclick="showtext()" >? ? <input type="button" value="取消設(shè)置" ?onclick="res()">? </form>? <script type="text/javascript">//定義"改變顏色"的函數(shù)function changecolor(){? ? var demo1=document.getElementById("text");? ? demo1.style.color="green";? ? demo1.style.backgroundColor="blue";}//定義"改變寬高"的函數(shù)function changewh(){? ? var demo2=document.getElementById("text");? ? demo2.style.width="200px";? ? demo2.style.height="300px";}//定義"隱藏內(nèi)容"的函數(shù)function hiddentext(){? ?var demo3=document.getElementById("text");? ?demo3.style.display="none";}//定義"顯示內(nèi)容"的函數(shù)function showtext(){? ? var demo4=document.getElementById("text").style.display="block";}//定義"取消設(shè)置"的函數(shù)function res(){? ? var demo5=confirm("是否取消設(shè)置?");? ? if(demo5==true){? ? ? ? text.style('');? ? }}
9 回答

qq_再見時(shí)光_0
TA貢獻(xiàn)6條經(jīng)驗(yàn) 獲得超4個贊
不僅缺少一個script結(jié)束標(biāo)簽,而且按鈕列中缺少對應(yīng)的id等于text。建議在每一個input標(biāo)簽中,分別寫上對應(yīng)的id,text1~text5,然后在根據(jù)id調(diào)用

于治y2
TA貢獻(xiàn)4條經(jīng)驗(yàn) 獲得超0個贊
少了一個id是text的元素,少了一個</script>,document.getElementById("text") 定義到全局會好一點(diǎn)吧

499978920
TA貢獻(xiàn)1條經(jīng)驗(yàn) 獲得超0個贊
document.getElementById("text") 看方法名就知道是查找Id=text的標(biāo)簽,而你的代碼里沒看見這個id。
添加回答
舉報(bào)
0/150
提交
取消