http://www.9cbs.net/expert/topicview1.asp?id=933535
/ * Related XML to 1 to N SELECT does not make history * /
function AttachXMLForSelect (xd, arr, defaultText, defaultValue) // xd: xmldom, arr: array of select {function EnsureString (str) {if (typeof (str) == "string") return str; if (str == null Return ""; try {return str ";} catch (x) {} return";} defaultText = Ensurestring (DefaultText); DefaultValue = Ensurestring (DefaultValue); DEFAULTVALUE
// Check the parameter IF (xd == null || xd.documentelement == null || arr == null || arr.length == 0) throw (New Error (-1, "invalid arguments");
// Convert into internal XD (Function (XMLDOM) {xd = new activXObject ("Microsoft.xmLDom"); xd.loadXML (XMLDom.xml);}) (XD)
// Release SELECT, replace it with uniqueid to store for (VAR i = 0; i // Set the first SELECT related XML Node as an XML root element Arr [0] .Node = xd.documentelement; // Associate the first SELECT REATTACHNODE (0); Var controller = { Handlechange: handlechange } Return Controller; / / Respond to the user's operation function overselectchange (Event) {handlechange (at.srcelement);} // Handling SELECT may be modified, confirm the back Select normal function handlechange (s) {// get the location in the Arr in Arr for (var index = 0; index // Relationally associated XML node if (node) {var xns = node.selectnodes ("item"); arr [index 1] .Node = xns.item (s.selected ";} else arr [index) 1] .Node = NULL; // Related to the next SELECT / * Association Recurns * / ReattachNode (INDEX 1);}} // Association, retrans part of a select to the specified Node Function ReattachNode (index) {// Take the current associated Node Var Node = arr [index] .Node; var pnode = null; if (index> 0) Pnode = arr [ Index] .Node; // Take the current select var s = document.getlementByid (arr [index] .unique); // clearly clear the content S. Innerhtml = "" " // If there is defaulttext, set one IF ((node == null || node.selectnodes ("item"). Length == 0) && defaultText) {var o = document.createElement ("option"); o. Value = defaultValue; o.innertext = defaultText; S.Appendchild (O); / / If the associated Node is empty, cancel the event association if (node == null) {if (arr [index] .attach) {s.detachevent ("onchange", OnsectChange); arr [index] .attach = false } / * Associated recursive * / handlechange (s); return;} // If node is not empty / / Re-association event if (arr [index] .attach == false) {s.attachevent ("onchange", OnsectChange); arr [index] .attach = true;} // Pall the value of the child into the value of Var xns = node.selectnodes ("item"); for (var i = 0; i //This one. . . Maybe you may not need. . . IF (S.Options.Length) s.selectedIndex = 0; / * Associated recursive * / handlechange (s);}} script> item text = "text211" value = "value211" />