我的代码剂量工作告诉我完整的代码,onclick show block working,onclick hide不工作。我的代码是:
function ul() {
console.log('show');
document.getElementById("ul").style.display="block";
}
function closed(){
console.log('closing');
document.getElementById("ul").style.display="none";
}
我的HTML代码是:
<div class="bar" onclick="ul()"><i class="fas fa-bars"></i></div>
<div class="bar"i></ onclick="closed()"><i class="fas fa-times"></i></div>
<div id="ul"> contents to be toggled </div>
答案 0 :(得分:0)
您正在使用close() which is native method of windows
。你可以not simply override that
。您需要更改关闭的函数名称。
我已将其从close()
更改为closed()
function ul() {
console.log('show');
document.getElementById("ul").style.display="block";
}
function closed(){
console.log('closing');
document.getElementById("ul").style.display="none";
}
<button onclick="ul()"> Show ul </button>
<button onclick="closed()"> Close ul </button>
<p id="ul"> contents to be toggled </p>