[英]Hide visible div on show another div in javascript php?
我有可見的div,我想在JavaScript中顯示另一個div時隱藏可見的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
,迭代所有節點並設置屬性
function shownote(id) {
var comments = document.getElementsByClassName('comment');
Array.prototype.forEach.call(comments, function(elem) {
elem.style.display = "none";
});
document.getElementById(id).style.display = "block";
}
document.getElementByClassName('comment').style.display = "none";
而不是hidden
,你必須使用none
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.