Menu med træstruktur
Jeg har denne menu:<HTML><HEAD><TITLE>JavaScript Menu 1.0</TITLE><SCRIPT LANGUAGE="JavaScript1.2"><!--
if (document.layers) NS4 = 1; else NS4 = 0; if (document.all) IE4 = 1; else IE4 = 0; function display(id, str) { if (NS4) { with (document[id].document) { open(); write(str); close(); } } else { document.all[id].innerHTML = str; } }; function repstr(_in,_rep) { out = ""; for(_c=0; _c<_rep; _c++) out = out + _in; return out }; function showtree(node,level,str,expand) { if ( node.childs() == 0 ) { str = str + repstr(" ",level*4) + "<A HREF=\"" + node.url + "\" TARGET=" + menu_frame + " onMouseOver=\"window.status='" + node.text + "';return true\" onMouseOut=\"window.status='';return true\">-" + node.text + "</A><BR>"; } else { if ( expand == 0 ) { str = str + repstr(" ",level*4) + "<A HREF=\"java script:toggle('" + node.name + "')\" onMouseOver=\"window.status='" + node.text + "';return true\" onMouseOut=\"window.status='';return true\">" + node.text + "</A><BR>"; } if ( expand == 1 ) { str = str + repstr(" ",level*4) + node.text + "<BR>"; } } if ( ( ( node.unfold == 1 ) || ( expand == 1 ) ) && ( node.childs() > 0 ) ) { for (node.movefirst() ; node.notlastchild() ; node.movenext() ) { str = showtree(node.getchild(),level + 1,str,expand); } } return str; }; function toggle(name) { node = findnode(MyNode,eval(name)); if ( node.unfold == 0 ) { node.unfold = 1; } else { node.unfold = 0; } updatemenu(); }; function updatemenu() { str = '<P><A HREF="java script:showhelp()">?</A> '; display("menu",showtree(MyNode,0,str,0) + "</P>"); }; function showhelp() { str = '<P><A HREF="java script:updatemenu()">!</A> <A HREF="java script:updatemenu()">menu</A><BR><BR>Click in the menu, to view the submenu and links.</P>'; display("menu",str); }; function Node_childs() { return this.child.length; }; function Node_movefirst() { this.cchild = 0; }; function Node_movenext() { this.cchild++; }; function Node_notlastchild() { if ( this.cchild < this.childs() ) return 1; else return 0; }; function Node_getchild() { return this.child[this.cchild]; }; function Node(_text,_url) { this.text = _text; this.url = _url; this.unfold = 0; this.child = []; this.cchild = 0; this.childs = Node_childs; this.notlastchild = Node_notlastchild; this.movefirst = Node_movefirst; this.movenext = Node_movenext; this.getchild = Node_getchild; this.name = Math.random(); return this; }; function findnode(node,name) { if ( node.name == name ) return node; if ( node.childs() > 0 ) { for (node.movefirst(); node.notlastchild() ; node.movenext() ) { temp = findnode(node.getchild(),name); if ( temp != null ) return temp; } } return null; }
//-- RET HER FOR OPSÆTNING AF MENU --
var menu_title = "JavaScript Menu";
var menu_frame = "_top";
var MyNode = new Node("Akvariet","");
MyNode.child[0] = new Node("Byg dit eget akvarium","akvariumartikler.asp?action=byg_selv");
MyNode.child[1] = new Node("Indret akvariet","akvariumartikler.asp?action=Indret_akvariet");
//--></SCRIPT><STYLE>
<!-- OPSÆTNING AF UDSEENDE -->
a {text-decoration: none; color: black;}
p {text-decoration: none; color: black;}
</STYLE></HEAD><BODY onLoad="if ( ( NS4 == 1 ) || ( IE4 == 1 ) ) setTimeout('updatemenu()',1)"><SCRIPT>document.write(menu_title);</SCRIPT><P><DIV ID="menu" STYLE="position: absolute;"><SCRIPT>if ( ( NS4 != 1 ) && ( IE4 != 1 ) ) document.write(showtree(MyNode,0,'',1))</SCRIPT><NOSCRIPT>Dette er en javascript menu. Din browser understøtter desværre ikke javascript</NOSCRIPT></DIV><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><BR><br><hr><center>Downloaded from: <a href="http://www.script.dk">Script.dk</a></center>
</BODY></HTML>
Fra script.dk
Den fungere fint, jeg har bare lige et problem da jeg ikke har en s.... forstand på javascript. Jeg ville nemlig gerne bruge denne menu flere gange på samme side, hvordan gør jeg det?
