亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

爽心悅目的代碼,但是this.index == oBtn.length - 1 && (oDiv.style.cssText = "");什么意思?

爽心悅目的代碼,但是this.index == oBtn.length - 1 && (oDiv.style.cssText = "");什么意思?

AllySu 2017-10-21 01:22:46
<!DOCTYPE?html?PUBLIC?"-//W3C//DTD?XHTML?1.0?Transitional//EN"?"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"> <html?xmlns="http://www.w3.org/1999/xhtml"> <head> <meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"?/> <title>控制div屬性</title> <style> #outer{width:500px;margin:0?auto;padding:0;text-align:center;} #div1{width:100px;height:100px;background:black;margin:10px?auto;display:block;} </style> <script> var?changeStyle?=?function?(elem,?attr,?value) { elem.style[attr]?=?value }; window.onload?=?function?() { var?oBtn?=?document.getElementsByTagName("input"); var?oDiv?=?document.getElementById("div1"); var?oAtt?=?["width","height","background","display","display"]; var?oVal?=?["200px","200px","red","none","block"]; for?(var?i?=?0;?i?<?oBtn.length;?i++) { oBtn[i].index?=?i; oBtn[i].onclick?=?function?() { this.index?==?oBtn.length?-?1?&&?(oDiv.style.cssText?=?""); changeStyle(oDiv,?oAtt[this.index],?oVal[this.index]) } } }; </script> </head> <body> <div?id="outer"> <input?type="button"?value="變寬"?/> <input?type="button"?value="變高"?/> <input?type="button"?value="變色"?/> <input?type="button"?value="隱藏"?/> <input?type="button"?value="重置"?/> <div?id="div1"></div> </div> </body> </html>代碼簡潔高效,但是this.index == oBtn.length - 1 && (oDiv.style.cssText = "");不大懂什么意思
查看完整描述

2 回答

?
慕虎5376285

TA貢獻2條經驗 獲得超2個贊

從功能效果上看 是用&&的特性代替了if? 當&&前面的==為真時則運行&&后面的? 當&&前面的==為假時則停止運行

查看完整回答
1 反對 回復 2017-10-23
?
慕虎5376285

TA貢獻2條經驗 獲得超2個贊

從功能效果上看 是用&&的特性代替了if? 當&&前面的==為真時則運行&&后面的? 當&&前面的==為假時則停止運行

查看完整回答
1 反對 回復 2017-10-23
  • AllySu
    AllySu
    看了大家的回復,明白了,謝謝
  • 2 回答
  • 0 關注
  • 2690 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號