完美運行,是不是最簡代碼
?<!--當點擊相應按鈕,執(zhí)行相應操作,為按鈕添加相應事件-->???? ?<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="取消設置"?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ù)???? ?function?cancel(){???????? ?if(cancel=true){???????????? ?text.style="none";????????}???????? ?else{????????????????????}????}?? ?</script></body></html>
以上代碼編輯后測試可運行相應要求,請各位大神看看是否為最簡化的代碼;
煩請指正和優(yōu)化,歡迎討論
2018-07-19
話說,,,為什么要用相等判斷啊,,if()就是判斷是否是ture的,,,在用confirm時就會得到ture或false,無論是哪一種改法我都覺得沒有必要判斷是否等于ture
2018-07-21
我即使是copy了你的代碼,點了按鈕,文字還是沒有變化= =
2018-07-20
change不是chenge.....
我強迫癥。。。。 =。=
2018-07-20
? ? function cancel(){
? ? ? ? var a=confirm("是否取消設置?");
? ? ? ? if(a==true){
? ? ? ? ? ? text.style="none";
? ? ? ? }
? ? ? ? else{
? ? ? ? document.write("為什么?");
? ? ? ? }
? ? }
最后取消設置哪里我忽略了要彈出確認,所以才那樣寫。。。
謝謝各位提醒,改為上面這樣。
我的本意為問是不是最簡化的代碼,不意被各位大哥發(fā)現(xiàn)了疏漏,先謝過
2018-07-19
樓上說得對
function cancel(){
var message = confirm("確認重置操作么?")
if(message){
text.style="none";
}
}
我覺得這樣也可以
2018-07-19
24行 ?if(confirm("要取消設置嗎"))
2018-07-19
....嘛,,,沒人嗎,,,,,,,,其實就24行有問題,,,要不就聲明var cancel=confirm("是否取消設置?");要不直接把括號里的改為if(confiem("是否取消設置?"))
2018-07-19
你是認真的嗎?
.......我掃一眼就看到24行的錯誤了,,,,,,,,,,(注:java中判斷相等時用==,賦值用=)