用strUserlist.split('|')實現分隔并賦給一個數組
用循環遍曆數組,用數組名[i].split('-')再次分隔
然后用你所給的條件判斷是否在线,最大值<当前值并作出作相應的動作(如修改樣式或加鏈接)

解决方案 »

  1.   

    IE测试通过,不清楚lz
    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>
      

  2.   

    最大值<当前值 @maxid<@currentid
      

  3.   

    不是只有两个,是有N多个.各位朋友在帮下我.
    ------------------------
    数据嘛,随便加几条都可以,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>
      

  4.   

    alert(ilen)
    注掉
    改成
    //alert(ilen)
      

  5.   

    谢谢lihui_shine(浪尖赏花),我要的不是点在线,就在线的人员显示,而是点人员的姓名,就弹出一个新窗口,新窗口的ID号就是数值中的ID号
      

  6.   


    <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>
      

  7.   

    非常感谢大家,就是我在点击时,只能打开chating.aspx,而不是chating.aspx?id=..
      

  8.   


    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這個文件
    再說我也不知道你這個文件到底為顯示些什么內容