如何用返回的xml的数据来动态填充div的值?返回的数据的行数是不确定的,是不是要重写这个Div了,详见. 不用,写个xsl解析一下就是了,嘿嘿 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 test.htm------------------------------<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"><title></title></head><body><xml id="test"><NewDataSet> <table> <user_name>006</user_name> <other_name>张表</other_name> <id>6</id> <sex>男</sex> </table> <table> <user_name>008</user_name> <other_name>王有在</other_name> <id>6</id> <sex>男</sex> </table> <table> <user_name>009</user_name> <other_name>我们的祖国</other_name> <id>6</id> <sex>男</sex> </table></NewDataSet></xml><script language="javascript">xml = document.getElementById("test").XMLDocument;xsl = new ActiveXObject( "Msxml2.DOMDocument");xsl.load( "test.xsl" );alert(xml.transformNode(xsl));</script></body></html><script></script>--------------------------test.xsl -----------------------------<?xml version="1.0" encoding="GB2312"?><xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform"><xsl:template match="/NewDataSet"> <xsl:for-each select="table"> <div class="talkrighttop"> <div class="talkrighttopxiao"> <xsl:choose> <xsl:when test="sex='男'"> 男<IMG src="images/men.gif"/> </xsl:when> <xsl:otherwise> 女<IMG src="images/women.gif"/> </xsl:otherwise> </xsl:choose> </div> <div class="talkrighttopbig"> <xsl:value-of select="other_name"/> </div> </div> </xsl:for-each></xsl:template></xsl:stylesheet> <div class="talkright" id="rightOnLine"> <div class="talkrighttop"> <div class="talkrighttopxiao"><IMG src="images/men.gif"></div> <div class="talkrighttopbig">张表</div> </div> <div class="talkrighttop"> <div class="talkrighttopxiao"><IMG src="images/men.gif"></div> <div class="talkrighttopbig">王有在</div> </div> <div class="talkrighttop"> <div class="talkrighttopxiao"><IMG src="images/women.gif"></div> <div class="talkrighttopbig">孙红</div> </div> <div class="talkrighttop"> <div class="talkrighttopxiao"><IMG src="images/women.gif"></div> <div class="talkrighttopbig">李红</div> </div> ......注:根据返回的数据行数来决定多少行,是动态的</div><xml id=x><NewDataSet> <table> <user_name>006</user_name> <other_name>张表</other_name> <id>6</id> <sex>男</sex> </table> <table> <user_name>008</user_name> <other_name>王有在</other_name> <id>6</id> <sex>男</sex> </table> <table> <user_name>009</user_name> <other_name>我们的祖国</other_name> <id>6</id> <sex>男</sex> </table></NewDataSet></xml><SCRIPT LANGUAGE="JavaScript"><!--var x=new ActiveXObject("Microsoft.XMLDOM")x.loadXML(document.all.x.innerHTML); //这个XML数据你自己搞var node = x.selectSingleNode("/NewDataSet");var str = "";if(node.hasChildNodes()){ for(var i=0; i<node.childNodes.length; i++) { var sex = node.childNodes[i].childNodes[3].text; var other_name = node.childNodes[i].childNodes[1].text; str += '<div class="talkrighttop">'; str += '<div class="talkrighttopxiao"><IMG src="images/'+ (sex=="男"? "men" : "women") +'.gif"></div>'; str += '<div class="talkrighttopbig">'+ other_name +'</div>'; str += '</div>'; }}document.getElementById("rightOnLine").innerHTML = str;//--></SCRIPT> firefox的xmldom和ms的很多地方不太一样我都是用foreach去寻找的,有没有firefox的编程手册的??比如.text在ff里用.textContent insert into 的时候需要取另一个表中的一个字段值怎么写SQL语句? 在线求解?纯js 求问重新加载的问题 js后面的参数a.js?time=123456 怎么获取time和123456 WEB 打印,如何实现打印多联 去掉字符串前后空格的函数? 一直困饶着我的问题 如何用javascript实现在框架之间传递参数 Jquery EasyUI DataGrid SubGrid 子表如何再嵌套子表 请教各位大神一个高德地图的问题 很难的问题,在线等 格式怎么就对不齐了呢?
------------------------------
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title></title>
</head>
<body>
<xml id="test">
<NewDataSet>
<table>
<user_name>006</user_name>
<other_name>张表</other_name>
<id>6</id>
<sex>男</sex>
</table>
<table>
<user_name>008</user_name>
<other_name>王有在</other_name>
<id>6</id>
<sex>男</sex>
</table>
<table>
<user_name>009</user_name>
<other_name>我们的祖国</other_name>
<id>6</id>
<sex>男</sex>
</table>
</NewDataSet>
</xml>
<script language="javascript">
xml = document.getElementById("test").XMLDocument;
xsl = new ActiveXObject( "Msxml2.DOMDocument");
xsl.load( "test.xsl" );
alert(xml.transformNode(xsl));
</script>
</body>
</html>
<script>
</script>--------------------------test.xsl -----------------------------
<?xml version="1.0" encoding="GB2312"?>
<xsl:stylesheet version="1.0" xmlns:xsl="http://www.w3.org/1999/XSL/Transform">
<xsl:template match="/NewDataSet">
<xsl:for-each select="table">
<div class="talkrighttop">
<div class="talkrighttopxiao">
<xsl:choose>
<xsl:when test="sex='男'">
男<IMG src="images/men.gif"/>
</xsl:when>
<xsl:otherwise>
女<IMG src="images/women.gif"/>
</xsl:otherwise>
</xsl:choose>
</div>
<div class="talkrighttopbig">
<xsl:value-of select="other_name"/>
</div>
</div>
</xsl:for-each>
</xsl:template>
</xsl:stylesheet>
<div class="talkrighttop">
<div class="talkrighttopxiao"><IMG src="images/men.gif"></div>
<div class="talkrighttopbig">张表</div>
</div>
<div class="talkrighttop">
<div class="talkrighttopxiao"><IMG src="images/men.gif"></div>
<div class="talkrighttopbig">王有在</div>
</div>
<div class="talkrighttop">
<div class="talkrighttopxiao"><IMG src="images/women.gif"></div>
<div class="talkrighttopbig">孙红</div>
</div>
<div class="talkrighttop">
<div class="talkrighttopxiao"><IMG src="images/women.gif"></div>
<div class="talkrighttopbig">李红</div>
</div> ......注:根据返回的数据行数来决定多少行,是动态的</div>
<xml id=x>
<NewDataSet>
<table>
<user_name>006</user_name>
<other_name>张表</other_name>
<id>6</id>
<sex>男</sex>
</table>
<table>
<user_name>008</user_name>
<other_name>王有在</other_name>
<id>6</id>
<sex>男</sex>
</table>
<table>
<user_name>009</user_name>
<other_name>我们的祖国</other_name>
<id>6</id>
<sex>男</sex>
</table>
</NewDataSet>
</xml>
<SCRIPT LANGUAGE="JavaScript">
<!--
var x=new ActiveXObject("Microsoft.XMLDOM")
x.loadXML(document.all.x.innerHTML); //这个XML数据你自己搞
var node = x.selectSingleNode("/NewDataSet");
var str = "";
if(node.hasChildNodes())
{
for(var i=0; i<node.childNodes.length; i++)
{
var sex = node.childNodes[i].childNodes[3].text;
var other_name = node.childNodes[i].childNodes[1].text;
str += '<div class="talkrighttop">';
str += '<div class="talkrighttopxiao"><IMG src="images/'+ (sex=="男"? "men" : "women") +'.gif"></div>';
str += '<div class="talkrighttopbig">'+ other_name +'</div>';
str += '</div>';
}
}
document.getElementById("rightOnLine").innerHTML = str;
//-->
</SCRIPT>