關于js改變css樣式的寫法
<!doctype?html> <html> <head> ????<meta?charset="utf-8"> ????<title>浮動去空格</title> ????<style> ????????button?{?margin:?0;?} ????????/*這里clear:both,為的就是當左浮動之后,這個p不會跟著去浮動,如果設置none,那么p元素會跟著浮動*/ ????????p?{?clear:?both;?} ????</style> </head> <body> <button>按鈕1</button> <button>按鈕2</button> <button>按鈕3</button> <button>按鈕4</button> <p><input?type="button"?id="trigger"?value="點擊按鈕浮動"></p> <script> ????var?trigger?=?document.getElementById("trigger"), ????????buttons?=?document.getElementsByTagName("button"); ????var?length?=?buttons.length; ????if?(trigger?&&?length?>?0)?{ ????????trigger.onclick?=?function()?{ ????????????for?(var?index?=?0;?index?<?length;?index?+=?1)?{ ????????????????buttons[index].style["cssFloat"?in?trigger.style??"cssFloat":?"styleFloat"]?=?"left"; ????????????} ????????}; ????} </script> </body> </html>
其中?buttons[index].style["cssFloat" in trigger.style? "cssFloat": "styleFloat"] = "left"; 這個是啥意思?沒見過這種寫法