CSS:隐藏与鼠标点击和展示上的JavaScript元素第二点击
ol{display: block;} // display: ""; throws an error in the console(FF)
HTML:
<!DOCTYPE html>
<html>
<head><script type="text/javascript">!js is here!</script>
<body>
<h2>Title</h2>
<input type="button" id="btn" value="expand" />
<ol>
<li>Value 1</li>
<li>Value 1</li>
<li>Value 1</li>
</ol>
</body>
</html>
的Javascript://尝试只是隐藏元素现在
window.onload = function() {
function expand() {
var ol = document.getElementByTagName('ol');
ol.style.display('none');
}
function init() {
var btn = document.getElementById('btn');
btn.addEventListener('click', expand, false);
}
}
我一直在寻找类似的东西,我找到的所有东西都使用了额外的库(utility.js,jquery e ),但为了学习的目的,我想在纯JS中做到这一点。
每个来源在线引用element.className = "newClass";
。我试图通过制作类.hide{display: none;}
和.show{display: "";}
,但它似乎没有做任何事情。然后我转向操纵风格(element.style.display("none");
),但这似乎也不奏效。
不应该是'ol.style.display =“none”'? – Patrick
你收到什么错误? –