我已经有一段时间了,我似乎无法破解它。我有一些 javascript 试图隐藏兄弟 div,除了通过函数传递的那个。这是html:
<div id = "chat_content">
<div id = "chat_content_1">This is div one</div>
<div id = "chat_content_2">This is div two</div>
<div id = "chat_content_3">This is div three</div>
</div>
这是javascript:
function showGroup(id)
{
// show the the div that was clicked
var e = document.getElementById(id);
e.style.display = 'block';
// hide the others divs under the same parent
var children = e.parentNode.childNodes;
for (var i = 0; i < children.length; i++)
{
if (children[i] != e)
{
children[i].style.display = 'none';
}
};
}
谢谢!和节日快乐:)