在javascript php中显示另一个div时隐藏可见div?

在javascript php中显示另一个div时隐藏可见div?,javascript,tags,hide,visible,Javascript,Tags,Hide,Visible,我有visible div,我想在javascript中显示另一个div时隐藏visible div 我的js:- `function shownote(id){ document.getElementById(id).style.display = "block"; document.getElementByClassName('comment').style.display = "hidden"; }` 我的代码:- `<td> <?php ech

我有visible div,我想在javascript中显示另一个div时隐藏visible div

我的js:-

`function shownote(id){
    document.getElementById(id).style.display = "block";
    document.getElementByClassName('comment').style.display = "hidden";
}`
我的代码:-

`<td>
    <?php echo $key; ?><br><input type='button' class="btn" value="Note"      onclick="shownote('comment<?php echo $unique; ?>')">
    <div class="comment" id="comment<?php echo $unique; ?>"  style="display:none;">
    <textarea id="notemenu" name="notemenu" placeholder="Note Here"></textarea>  <br>
    <input type="button" value="Submit"><a href>Cancel</a>
    </div> 
</td>`
`

hidden
不是用于显示的有效属性。请尝试使用display='none'。另请注意,
getElementsByClassName
(此处也请更正输入错误)将返回
nodelist
,迭代所有节点并设置属性

函数shownote(id){
var comments=document.getElementsByClassName('comment');
Array.prototype.forEach.call(注释、函数(elem)){
elem.style.display=“无”;
});
document.getElementById(id).style.display=“block”;
}
hidden
不是用于显示的有效属性。请尝试使用display='none'。另请注意,
getElementsByClassName
(此处也请更正输入错误)将返回
nodelist
,迭代所有节点并设置属性

函数shownote(id){
var comments=document.getElementsByClassName('comment');
Array.prototype.forEach.call(注释、函数(elem)){
elem.style.display=“无”;
});
document.getElementById(id).style.display=“block”;
}
您必须使用
none


您必须使用
none
display='none'
而不是
hidden
您必须使用
display='none'
也不起作用
getElementByClassName
中有输入错误,它必须是
getElementsByClassName
document.getElementByClassName('comment')
将返回类似nodelist的数组,而不是像
getElementById
这样的单个元素,它在
getElementByClassName
中有输入错误,它必须是
getElementsByClassName
<代码>文档.getElementByClassName('注释')
将返回类似于nodelist的数组,而不是类似于
getElementById的单个元素。这不适用于此代码显示为div也隐藏。它将删除所有类为
注释的元素。这不适用于此代码显示为div也隐藏。它将删除所有类为
注释的元素。
document.getElementByClassName('comment').style.display = "none";