登录  
 加关注
   显示下一条  |  关闭
温馨提示!由于新浪微博认证机制调整,您的新浪微博帐号绑定已过期,请重新绑定!立即重新绑定新浪微博》  |  关闭

整理

挺好

 
 
 

日志

 
 
 
 

JS读取XML模板自动生成Table  

2008-08-19 09:53:13|  分类: Web |  标签: |举报 |字号 订阅

  下载LOFTER 我的照片书  |

function setting(gk){
 //建立dom对象
xmlDoc = new ActiveXObject('Microsoft.XMLDOM');
 //设置是否同步
xmlDoc.async = false;
//加载文档
xmlDoc.load("setting.xml");
//创建根元素节点
var obj = document.createElement("table");
var tbody = document.createElement("tbody");
//根据参数gk得到其子节点的元素个数
var n = xmlDoc.getElementsByTagName(gk)[0].childNodes;
//根据其长度遍历其所有的子节点
for(var i=0;i<n.length;i++){
 //得到子节点的名字
 var name=xmlDoc.getElementsByTagName(gk)[0].childNodes(i).nodeName;
 //得到子节点的name属性的值
 var values=xmlDoc.getElementsByTagName(gk)[0].childNodes(i).getAttribute('name');
 //以每行三列的方式来布局
 if((i+1)==1||(i+1)==4||(i+1)==7||(i+1)==10||(i+1)==13||(i+1)==16||(i+1)==19||(i+1)==22||(i+1)==25||(i+1)==28||(i+1)==31||(i+1)==34||(i+1)==37||(i+1)==40||(i+1)==43||(i+1)==46||(i+1)==49||(i+1)==52||(i+1)==55||(i+1)==58){
 //创建节点
 var tr = document.createElement("tr");
    var td = document.createElement("td");
 //添加属性
 td.setAttribute("noWrap","true");
 td.setAttribute("width","12.5%");
 td.setAttribute("class","content_field");
    td.innerText = values;
  var tds = document.createElement("td");
 tds.setAttribute("noWrap","true");
 tds.setAttribute("width","25%");
    var input = document.createElement("input");
 input.setAttribute("id",name);
 input.setAttribute("type","text");
 input.setAttribute("size","8");
 input.setAttribute("style","font-weight:bold");
 input.setAttribute("value","<fmt:formatNumber value='${ajjc452Value.BZJS}' pattern='0.00000'/>");
 input.setAttribute("readOnly","true");
 //子节点添加到父节点
 tds.appendChild(input);
 tr.appendChild(td);
 tr.appendChild(tds);
 }else if((i+1)==3||(i+1)==6||(i+1)==9||(i+1)==12||(i+1)==15||(i+1)==18||(i+1)==121||(i+1)==24||(i+1)==27||(i+1)==30||(i+1)==33||(i+1)==36||(i+1)==39||(i+1)==42||(i+1)==45||(i+1)==48||(i+1)==51||(i+1)==54||(i+1)==57||(i+1)==60) {
 var td = document.createElement("td");
 td.setAttribute("noWrap","true");
 td.setAttribute("width","12.5%");
 td.setAttribute("class","content_field");
    td.innerText = values;
 var tds = document.createElement("td");
 td.setAttribute("noWrap","true");
 tds.setAttribute("width","25%");
    var input = document.createElement("input");
 input.setAttribute("id",name);
 input.setAttribute("type","text");
 input.setAttribute("size","8");
 input.setAttribute("style","font-weight:bold");
 input.setAttribute("value","<fmt:formatNumber value='${ajjc452Value.BZJS}' pattern='0.00000'/>");
 input.setAttribute("readOnly","true");
 tr.appendChild(td);
 tr.appendChild(tds);
    tds.appendChild(input);
  
 }else{
 var td = document.createElement("td");
 td.setAttribute("noWrap","true");
 td.setAttribute("width","12.5%");
 td.setAttribute("class","content_field");
    td.innerText = values;
  var tds = document.createElement("td");
 td.setAttribute("noWrap","true");
 tds.setAttribute("width","25%");
    var input = document.createElement("input");
 input.setAttribute("id",name);
 input.setAttribute("type","text");
 input.setAttribute("size","8");
 input.setAttribute("style","font-weight:bold");
 input.setAttribute("value","<fmt:formatNumber value='${ajjc452Value.BZJS}' pattern='0.00000'/>");
 input.setAttribute("readOnly","true");
 tds.appendChild(input);
 tr.appendChild(td);
 tr.appendChild(tds);
 }
 tbody.appendChild(tr);
}
   obj.setAttribute("class","normal1_table");
   obj.setAttribute("cellSpacing","1");
   obj.setAttribute("cellPadding","4");
   obj.setAttribute("width","100%");
   obj.setAttribute("align","center");
   obj.setAttribute("height","450");
   obj.setAttribute("border","0");
   obj.appendChild(tbody);
   //把根节点添加到指定的Form中
   document.all.frm.appendChild(obj);}

  评论这张
 
阅读(1396)| 评论(0)

历史上的今天

评论

<#--最新日志,群博日志--> <#--推荐日志--> <#--引用记录--> <#--博主推荐--> <#--随机阅读--> <#--首页推荐--> <#--历史上的今天--> <#--被推荐日志--> <#--上一篇,下一篇--> <#-- 热度 --> <#-- 网易新闻广告 --> <#--右边模块结构--> <#--评论模块结构--> <#--引用模块结构--> <#--博主发起的投票-->
 
 
 
 
 
 
 
 
 
 
 
 
 
 

页脚

网易公司版权所有 ©1997-2018