如果style属性已设置为display:none;如何将其更改为display:block;什么时候调用toggleControls函数?
function toggleControls() {
var leControls = document.getElementsByClassName('le-controls');
for(var i = 0; i < leControls.length; i++) { leControls[i].style.display = 'none'; }
}
答案 0 :(得分:2)
您可以检查它是否已经none
:
var style, leControls = document.getElementsByClassName('le-controls');
for (var i = 0; i < leControls.length; i++) {
if ('none' == leControls[i].style.display) {
style = 'block';
}
else {
style = 'none';
}
leControls[i].style.display = style;
}