有点hackish的:(见http://jsfiddle.net/vy6nS/30/)
window.onload = function() {
var elems1 = document.getElementsByClassName("expander");
for (i = 0; i < elems1.length; i++) {
elems2 = elems1[i].childNodes;
for (x = 0; x < elems2.length; x++) {
if (elems2[x].className == "toggle") elems2[x].onclick = function() {
showMore(0, this);
};
else if (elems2[x].className == "showMoreText") {
elems2[x].onmouseover = function() {
showChilds("block", this);
};
elems2[x].onmouseout = function() {
showChilds("none", this);
};
}
}
}
};
function get_nextsibling(n) {
x = n.nextSibling;
while (x.nodeType != 1) {
x = x.nextSibling;
}
return x;
}
function showChilds(disp, elem) {
get_nextsibling(elem).style.display = disp;
}
function showMore(disp, elem) {
var children = elem.parentNode.childNodes;
for (i = 0; i < children.length; i++) {
if (disp == 0 && children[i].className == "showMoreText") {
children[i].style.display = children[i].style.display == "none" ? "block" : "none";
}
}
}
你能澄清你正在努力实现的结果呢?小提琴很好,但在问题本身中查看代码/期望输出是有帮助的,以最大限度地提高人们帮助的机会。 – Utkanos 2012-07-12 17:54:37
1)你点击“点击这里查看更多信息”,然后“弹出,你会发现更多的信息”,当你将鼠标悬停在“这里,你会发现更多的信息”时,你会得到更多的div更多信息。所以它的显示/隐藏效果,添加了鼠标悬停以获取更多信息 - 基本上提供了3种不同级别的信息。第二级也有4个不同的文本区域。 – user1521577 2012-07-12 17:55:38
请注意您的鼠标移动想法如何转化为移动用户。 – 2016-08-09 16:50:48