完美運(yùn)行,是不是最簡(jiǎn)代碼
?<!--當(dāng)點(diǎn)擊相應(yīng)按鈕,執(zhí)行相應(yīng)操作,為按鈕添加相應(yīng)事件-->???? ?<input?type="button"?value="改變顏色"?onclick="colorchenge()"?>?????? ?<input?type="button"?value="改變寬高"?onclick="sizechenge()">???? ?<input?type="button"?value="隱藏內(nèi)容"?onclick="hideelement()">???? ?<input?type="button"?value="顯示內(nèi)容"?onclick="nohideelement()">???? ?<input?type="button"?value="取消設(shè)置"?onclick="cancel()">??</form>?? ?<script?type="text/javascript">//定義"改變顏色"的函數(shù)???? ?var?text=document.getElementById("txt");???? ?function?colorchenge(){???????? ?text.style.color="red";???????? ?text.style.backgroundColor="#CCC";????} ?//定義"改變寬高"的函數(shù)???? ?function?sizechenge(){???????? ?text.style.width="800px";???????? ?text.style.height="600px";????} ?//定義"隱藏內(nèi)容"的函數(shù)???? ?function?hideelement(){???????? ?text.style.display="none";????} ?//定義"顯示內(nèi)容"的函數(shù)???? ?function?nohideelement(){???????? ?text.style.display="block";?????} ?//定義"取消設(shè)置"的函數(shù)???? ?function?cancel(){???????? ?if(cancel=true){???????????? ?text.style="none";????????}???????? ?else{????????????????????}????}?? ?</script></body></html>
以上代碼編輯后測(cè)試可運(yùn)行相應(yīng)要求,請(qǐng)各位大神看看是否為最簡(jiǎn)化的代碼;
煩請(qǐng)指正和優(yōu)化,歡迎討論
2018-07-19
話說(shuō),,,為什么要用相等判斷啊,,if()就是判斷是否是ture的,,,在用confirm時(shí)就會(huì)得到ture或false,無(wú)論是哪一種改法我都覺(jué)得沒(méi)有必要判斷是否等于ture
2018-07-21
我即使是copy了你的代碼,點(diǎn)了按鈕,文字還是沒(méi)有變化= =
2018-07-20
change不是chenge.....
我強(qiáng)迫癥。。。。 =。=
2018-07-20
? ? function cancel(){
? ? ? ? var a=confirm("是否取消設(shè)置?");
? ? ? ? if(a==true){
? ? ? ? ? ? text.style="none";
? ? ? ? }
? ? ? ? else{
? ? ? ? document.write("為什么?");
? ? ? ? }
? ? }
最后取消設(shè)置哪里我忽略了要彈出確認(rèn),所以才那樣寫。。。
謝謝各位提醒,改為上面這樣。
我的本意為問(wèn)是不是最簡(jiǎn)化的代碼,不意被各位大哥發(fā)現(xiàn)了疏漏,先謝過(guò)
2018-07-19
樓上說(shuō)得對(duì)
function cancel(){
var message = confirm("確認(rèn)重置操作么?")
if(message){
text.style="none";
}
}
我覺(jué)得這樣也可以
2018-07-19
24行 ?if(confirm("要取消設(shè)置嗎"))
2018-07-19
....嘛,,,沒(méi)人嗎,,,,,,,,其實(shí)就24行有問(wèn)題,,,要不就聲明var cancel=confirm("是否取消設(shè)置?");要不直接把括號(hào)里的改為if(confiem("是否取消設(shè)置?"))
2018-07-19
你是認(rèn)真的嗎?
.......我掃一眼就看到24行的錯(cuò)誤了,,,,,,,,,,(注:java中判斷相等時(shí)用==,賦值用=)