日期:2014-05-16 浏览次数:20401 次
<html> <head> <script language="javascript"> function change(obj) { if(obj.innerText=="[-]") { obj.innerText="[+]"; }else{ obj.innerText="[-]"; } } </script> </head> <body> <div> <p><span onclick="change(this)">[-]</span>aaa<p/> <ul> <li>aaaaaa</li> <li>aaaaaa</li> <li>aaaaaa</li> </ul> <p><span onclick="change(this)">[-]</span>bbb<p/> <ul> <li>bbbbbb</li> <li>bbbbbb</li> <li>bbbbbb</li> </ul> <p><span onclick="change(this)">[-]</span>ccc<p/> <ul> <li>cccccc</li> <li>cccccc</li> <li>cccccc</li> </ul> </div> </body> </html>
function change(obj) { if (obj.innerText == "[-]") { obj.innerText = "[+]"; next(obj.parentNode).style.display = "none"; } else { obj.innerText = "[-]"; next(obj.parentNode).style.display = "block"; } } function next(elem) {//获得下一个元素节点 do { elem = elem.nextSibling; } while (elem && elem.nodeType != 1);//nodetype=1是元素节点 return elem; }