Star-∂ємση
2018-03-08 09:48
<!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"; 这个是啥意思?没见过这种写法
还没有人回答问题,可以看看其他问题
CSS深入理解之float浮动
75954 学习 · 467 问题
相似问题