使用Javascript更改预定义的样式属性

时间:2013-03-13 00:27:14

标签: javascript

如果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'; }
}

1 个答案:

答案 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;
}