<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312"> <title>new page</title> <script> strUserlist="1-小李-25-27-f1.gif-0|2-小三-12-12-f2.gif-1"; var userArr=strUserlist.split("|"); var len=userArr.length;function a(){ removeAllTR(); for(var i=0;i<len;i++){ var newArr=userArr[i].split("-"); var ilen=newArr.length;
var trObj=document.createElement("tr"); trObj.onclick=user(newArr[0]);
if(parseInt(newArr[5])==1) trObj.style.color="#ff0000"; var tdObj1=document.createElement("td"); tdObj1.innerText=newArr[4]; //這里你換成innerHtml="<img src="+newArr[4]+">";就可以加載圖片了 trObj.appendChild(tdObj1); var tdObj2=document.createElement("td");
tdObj2.innerText=newArr[1]; trObj.appendChild(tdObj2); var table=document.getElementById("t1"); table.firstChild.appendChild(trObj);} } function removeAllTR(){ var table=document.getElementById("t1"); var len=table.rows.length; for(var i=1;i<len;i++){ table.deleteRow(i); } } function user(id){ return function(){ window.open("chating.aspx?id="+id); } } </script> </head><body onload=a()> <table id=t1 border=1> <TR><TD>繷钩</TD><TD>name</TD></TR> </table></body> </html>
3.当最大值<当前值时:
是有什么条件?
所以只做了前2个,lz自己稍微改改吧<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>new page</title>
<script>
strUserlist="1-小华-25-27-f1.gif-0|2-小刘-12-12-f2.gif-1";
var userArr=strUserlist.split("|");
var len=userArr.length;function a(type){
removeAllTR();
for(var i=0;i<len;i++){
var newArr=userArr[i].split("-");
var ilen=newArr.length;
if(newArr[ilen-1]==type){
var trObj=document.createElement("tr");
trObj.onclick=user(newArr[0]);
var tdObj1=document.createElement("td");
tdObj1.innerText=newArr[4];
trObj.appendChild(tdObj1);
var tdObj2=document.createElement("td");
tdObj2.innerText=newArr[1];
trObj.appendChild(tdObj2);
var table=document.getElementById("t1");
table.firstChild.appendChild(trObj);
}
}
}
function removeAllTR(){
var table=document.getElementById("t1");
var len=table.rows.length;
for(var i=1;i<len;i++){
table.deleteRow(i);
}
}
function user(id){
return function(){
window.open("chating.aspx?id="+id);
}
}
</script>
</head><body>
<table id=t1 border=1>
<TR><TD>头像</TD><TD>name</TD></TR>
</table>
<input type=button value="在线" onclick=a(1)>
<input type=button value="不在线" onclick=a(0)>
</body>
</html>
------------------------
数据嘛,随便加几条都可以,lz不是要我帮你建表添数据吧
strUserlist里面自己加
因为时间有限,只能做到下面效果,lz看着自己改改吧
<html><head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>new page</title>
<script>
strUserlist="1-小华-25-27-f1.gif-0|2-小刘-12-12-f2.gif-1|3-小华-25-27-f1.gif-0|4-小刘-12-12-f2.gif-1";
var userArr=strUserlist.split("|");
var len=userArr.length;function a(type){
removeAllTR();
for(var i=0;i<len;i++){
var newArr=userArr[i].split("-");
var ilen=newArr.length;
if(newArr[ilen-1]==type){
var trObj=document.createElement("tr");
if(type==1){trObj.style.backgroundColor="green";}
else{trObj.style.backgroundColor="#cccccc";}
trObj.onclick=user(newArr[0]);
var tdObj1=document.createElement("td");
tdObj1.innerText=newArr[4];
trObj.appendChild(tdObj1);
var tdObj2=document.createElement("td");
tdObj2.innerText=newArr[1];
trObj.appendChild(tdObj2);
var table=document.getElementById("t1");
table.firstChild.appendChild(trObj);
}
}
}
function removeAllTR(){
var table=document.getElementById("t1");
var ilen=table.rows.length;
alert(ilen)
for(var i=ilen-1;i>0;i--){
table.deleteRow(i);
}
}
function user(id){
return function(){
window.open("chating.aspx?id="+id);
}
}
</script>
</head><body>
<table id=t1 border=1>
<TR><TD>头像</TD><TD>name</TD></TR>
</table>
<input type=button value="在线" onclick=a(1)>
<input type=button value="不在线" onclick=a(0)>
</body>
</html>
注掉
改成
//alert(ilen)
<html><head><meta http-equiv="Content-Type" content="text/html; charset=gb2312">
<title>new page</title>
<script>
strUserlist="1-小李-25-27-f1.gif-0|2-小三-12-12-f2.gif-1";
var userArr=strUserlist.split("|");
var len=userArr.length;function a(){
removeAllTR();
for(var i=0;i<len;i++){
var newArr=userArr[i].split("-");
var ilen=newArr.length;
var trObj=document.createElement("tr");
trObj.onclick=user(newArr[0]);
if(parseInt(newArr[5])==1)
trObj.style.color="#ff0000";
var tdObj1=document.createElement("td");
tdObj1.innerText=newArr[4]; //這里你換成innerHtml="<img src="+newArr[4]+">";就可以加載圖片了
trObj.appendChild(tdObj1);
var tdObj2=document.createElement("td");
tdObj2.innerText=newArr[1];
trObj.appendChild(tdObj2);
var table=document.getElementById("t1");
table.firstChild.appendChild(trObj);}
}
function removeAllTR(){
var table=document.getElementById("t1");
var len=table.rows.length;
for(var i=1;i<len;i++){
table.deleteRow(i);
}
}
function user(id){
return function(){
window.open("chating.aspx?id="+id);
}
}
</script>
</head><body onload=a()>
<table id=t1 border=1>
<TR><TD>繷钩</TD><TD>name</TD></TR>
</table></body>
</html>
function user(id){
return function(){
showModalDialog("chating.aspx?id="+id,"window","dialogWidth=500px;dialogHeight=350px;dialogTop=200;dialogLeft=250;help=no;status=no;scrollBar=no")
//window.open("chating.aspx?id="+id);
}
}
前提是你必須有chating.apsx這個文件
再說我也不知道你這個文件到底為顯示些什么內容