关于使用innerHTML替换的问题(在线等.....)

ypchengmsdn 2010-01-26 02:46:02

本人在项目中使用到innerHTML替换,在页面是这样的:
<tr >
<td id="show${airLine_index}"></td>
</tr>
我在页面里是将一个list遍历,上面的这段代码是动态的,
后台处理 js:

// 替换
function replaseStr(value){
var flight = value;
var showIndex = document.getElementById("show"+indexArr);
showIndex.innerHTML = flight;
}

//解析返回xml的方法
function parseMessage(){
//responseText 纯文本数据
var xmlDoc = XMLHttpReq.responseXML;
if (xmlDoc == null) {
return ;
}
var list = xmlDoc.getElementsByTagName('list');
var strFlight = "";
var strStringBuff ="";
var strStart = "<table align='center'><tr>"
+"<td width=160>舱等</td>"
+"<td width=160>价格</td>"
+"<td width=174>座位数</td>"
+"<td width=160>折扣</td>"
+"<td width=160>预订</td></tr>";
var strEnd = "</table>";
alert(list.length);
if (list.length == 0) {
strStringBuff +="目前没有该航班的信息!";

} else {
for(var i=0;i<list.length;i++) {
var berthEterm = list[i].childNodes[0].firstChild.nodeValue;
var realPrice = list[i].childNodes[1].firstChild.nodeValue;
var berthDigit = list[i].childNodes[2].firstChild.nodeValue;
var realPricesEnd = list[i].childNodes[3].firstChild.nodeValue;
if (realPricesEnd == 0) {
strStringBuff += "<tr><td width='160'>"+berthEterm+
"</td><td width='160'><font color='red'>¥"+realPrice
+"</font></td><td width='174'>"+berthDigit
+"</td><td width='160'><a href=''><font color='red'>预订 </font></a></td></tr><br/>";
} else {
strStringBuff += "<tr><td width=60>"+berthEterm+
"</td><td width='160'><font color='red'>¥"+realPrice
+"</font></td><td width='174'>"+berthDigit
+"</td><td width='160'>"+realPricesEnd
+"</td><td width='160'><a href=''><font color='red'>预订</font></a></td></tr><br/>";
}
}
strFlight += strStart+strStringBuff+strEnd;
replaseStr(strFlight);
}
}

上面的这段代码是解析xml的数据,你不看也可以,主要是替换为<table><tr><td>.....之类的html语言。
现在就是说格式不正确,页面我是用循环遍历的,每一个<tr>下面都有一个:
<tr >
<td id="show${airLine_index}"></td>
</tr>
所以现在格式不知如何是好??
...全文
285 6 打赏 收藏 举报
写回复
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuetao121 2010-02-01
  • 打赏
  • 举报
回复
提醒你,如果你是给文本域值的话,请给value,直接给innerHTML的时候,换行符号会失效。
需要你自己转换成htmlcode。
草根醉秋意 2010-02-01
  • 打赏
  • 举报
回复
大清早赶起来接分
itliyi 2010-02-01
  • 打赏
  • 举报
回复
gx jf
ypchengmsdn 2010-01-31
  • 打赏
  • 举报
回复
谢谢以上各位,问题已经解决了。
time5 2010-01-26
  • 打赏
  • 举报
回复
最好是在后台解析,用 dom4j会更容易些的
打字员 2010-01-26
  • 打赏
  • 举报
回复
("show"+indexArr);

indexArr ?

相关推荐
发帖
JavaScript

8.7w+

社区成员

Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
帖子事件
创建了帖子
2010-01-26 02:46
社区公告
暂无公告