100分求一js ,谢谢各位大虾们
<table style= "display:none " id=tb1 name=tb1>
<tr id=a1>
<td>
新闻标题a
</td>
<tr>
<tr id=a2>
<td>
新闻标题b
</td>
<tr>
<tr id=a3>
<td>
新闻标题c
</td>
<tr>
<tr id=a4>
<td>
新闻标题d
</td>
<tr>
</table>
以上为一table表格 做隐藏
<table id=tb2 name=tb1>
<script language=javascript>
//这里实现一个JS效果
//一个变量 titlemenu= "a1|a4|a2| ",以 "| "做分割,对字符串进行以 "| "的分割读取,假如读到a1 就document.write 上面的id为a1的那个tr的全部代码.依次循环titlemenu中的分割值并按照titlemenu变量中的排序进行显示
</script>
</table>
谢谢各位大虾们
------解决方案--------------------var titlemenu= "a1|a4|a2| ";
var titleArr = titlemenu.split( "| ");
for(var i=0; i < titleArr.length; i++) {
var tr = document.getElementById(titleArr[0]);
if(tr == null) continue;
document.write(tr.innerHTML);
}
------解决方案-------------------- <table style= "display:none " id=tb1 name=tb1>
<tr id=a1>
<td>
新闻标题a
</td>
<tr>
<tr id=a2>
<td>
新闻标题b
</td>
<tr>
<tr id=a3>
<td>
新闻标题c
</td>
<tr>
<tr id=a4>
<td>
新闻标题d
</td>
<tr>
</table>
<script>
function goWrite(){
var titlemenu= "a1|a4|a2|a3 ";
var strs = titlemenu.split( "| ");
var html = " ";
for(var i=0;i <strs.length;i++){
var obj = document.getElementById(strs[i]);
html += obj.firstChild.innerHTML + " <br /> ";
}
document.write(html);
}
</script>
<input type= "button " value= "gogo " onclick= "goWrite(); " />
------解决方案--------------------对 Jinglecat(晓风残月 > > 问题需简洁,错误要详细) 的稍作了修改
<table border =1>
<script language = "javascript ">
var titlemenu= "a1|a4|a2| ";
var titleArr = titlemenu.split( "| ");
for(var i=0; i < titleArr.length; i++) {
var tr = document.getElementById(titleArr[i]);
if(tr == null) continue;
document.write( " <tr> " + tr.innerHTML + " </tr> ");
}
</script>