Amigo(33056009) 17:46:48问个问题若我的xml的内容如下:
我已取到options数组了,alert出options的长度是2,我想遍历取得各数组中的value和textContext,该怎么写js啊
告诉我个关键字去google也好 BeanSoft(9991483) 17:46:50哈,去看看 xloadtree 的实现即可 Amigo(33056009) 17:48:01晕
BeanSoft(9991483) 17:47:52 // there is one extra level of tree elements var root = oXmlDoc.documentElement;
// loop through all tree children var cs = root.childNodes; var l = cs.length; for (var i = 0; i < l; i++) { if (cs[i].tagName == "tree") { bAnyChildren = true; bIndent = true; jsParentNode.add( _xmlTreeToJsTree(cs[i]), true); } } BeanSoft(9991483) 17:48:03// Converts an xml tree to a js tree. See article about xml tree formatfunction _xmlTreeToJsTree(oNode) { // retreive attributes var text = oNode.getAttribute("text"); var action = oNode.getAttribute("action"); BeanSoft(9991483) 17:48:27<?xml version="1.0"?>
<tree> <tree text="Load "tree1.xml"" src="tree1.xml" /> <tree text="Loaded Item 1" action="http://webfx.eae.net" /> <tree text="Loaded Item 2"> <tree text="Loaded Item 2.1" action="javascript:alert(2.1)" /> </tree> <tree text="Loaded Item 3 (with target)" action="http://www.google.com" target="_new" /> <tree text="Load "tree1.xml"" src="tree1.xml" /></tree> Amigo(33056009) 17:49:41多谢 问题解决,修改后的js如下: