Select 对象如何邦定一个XML?

DwNet 2003-06-19 02:25:05
<body>
<xml ID="dbck">
<VehicleList>
<Vehicle>
<vID>1</vID>
<DriverID>A</DriverID>
</Vehicle>
<Vehicle>
<vID>2</vID>
<DriverID>B</DriverID>
</Vehicle>
<Vehicle>
<vID>3</vID>
<DriverID>C</DriverID>
</Vehicle>
</VehicleList>
</xml>
<table width="100%" height="135" border="0">
<tr>
<td width="14%"> </td>
<td width="86%">
<select name="TestSelect" id="TestSelect" DATASRC="dbck">
<option value="" DATAFLD="DriverID"></option> ?????????
</select></td>
</tr>
</table>
</body>
</html>
...全文
24 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
DwNet 2003-06-24
  • 打赏
  • 举报
回复
以上都是通过解析XML得到加载。和邦定有区别,可能不能绑定。不过非常感谢各位
现在结帖。
ssm1226 2003-06-19
  • 打赏
  • 举报
回复
select的绑定,只是将select原有数据与数据源第一个节点值相等的option 的selected设为true


要想实现数据添加,用DOM

例如:


<body>
<xml ID="dbck">
<VehicleList>
<Vehicle>
<vID>1</vID>
<DriverID>A</DriverID>
</Vehicle>
<Vehicle>
<vID>2</vID>
<DriverID>B</DriverID>
</Vehicle>
<Vehicle>
<vID>3</vID>
<DriverID>C</DriverID>
</Vehicle>
</VehicleList>
</xml>
<table width="100%" height="135" border="0">
<tr>
<td width="14%"> </td>
<td width="86%">
<select name="TestSelect" id="TestSelect" DATASRC="#dbck" DATAFLD="DriverID">
<option value="C">C</option>
<option value="A">A</option>
<option value="B">B</option>
</select></td>
</tr>
</table>
</body>
kingdomzhf 2003-06-19
  • 打赏
  • 举报
回复
和绑定有区别
seabell 2003-06-19
  • 打赏
  • 举报
回复
<script>
function readxml(){
var xmldoc=dbck.XMLDocument;
var node=xmldoc.selectSingleNode('//VehicleList');
var subnodes=node.childNodes;
var objSel=document.all.TestSelect;
for(var i=0;i<subnodes.length;i++){
var subnode=subnodes(i);
var o=document.createElement("option");
o.text=subnode.childNodes(1).text;
o.value=subnode.childNodes(0).text;
objSel.add(o);
}
}
</script>
<body onload=readxml()>
<xml ID="dbck">
<VehicleList>
<Vehicle>
<vID>1</vID>
<DriverID>A</DriverID>
</Vehicle>
<Vehicle>
<vID>2</vID>
<DriverID>B</DriverID>
</Vehicle>
<Vehicle>
<vID>3</vID>
<DriverID>C</DriverID>
</Vehicle>
</VehicleList>
</xml>
<table width="100%" height="135" border="0">
<tr>
<td width="14%"> </td>
<td width="86%">
<select name="TestSelect">
</select>
</td>
</tr>
</table>
</body>

87,910

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧