0

如果 style 属性已经设置为 display: none; 如何将其更改为显示:块;调用 toggleControls 函数时?

function toggleControls() {
    var leControls = document.getElementsByClassName('le-controls'); 
    for(var i = 0; i < leControls.length; i++) { leControls[i].style.display = 'none'; }
}
4

1 回答 1

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;
}
于 2013-03-13T00:29:32.513 回答