本帖最后由 ouyangbo100 于 2014-03-25 15:47:41 编辑

解决方案 »

  1.   

    有一串字符串switchChannelStatus代表开关的路数,比如“1,0,1,1,1"。
      

  2.   

    var channel = '1,0,1,1,1';
    var chsp = channel.split(',');
    var str = "";
        for(var i=1;i<=chsp.length;i++){         str += chsp[i-1] == 1 ? "<div>第"+i+"路:<input type=\"radio\" checked = \"checked\" value=\"1\" id=\"rdc"+i+"1\" name=\"instruction_"+i+"\"><label for=\"rdc"+i+"1\">开启</label> <input type=\"radio\" value=\"0\" id=\"rdc"+i+"0\" name=\"instruction_"+i+"\"><label for=\"rdc"+i+"0\">关闭</label></div>" : "<div>第"+i+"路:<input type=\"radio\" value=\"1\" id=\"rdc"+i+"1\" name=\"instruction_"+i+"\"><label for=\"rdc"+i+"1\">开启</label> <input type=\"radio\" checked = \"checked\" value=\"0\" id=\"rdc"+i+"0\" name=\"instruction_"+i+"\"><label for=\"rdc"+i+"0\">关闭</label></div>";
        }
        
         document.write(str);
      

  3.   


    话说,我自己这样写
    $.each(channel, function(i){
    if(channel[i]==1){
    str +="<div>第"+i+"路:<input type=\"radio\" value=\"1\" checked=\"checked\" id=\"rdc"+i+"1\" name=\"instruction_"+i+"\"><label for=\"rdc"+i+"1\">开启</label> <input type=\"radio\" value=\"0\" id=\"rdc"+i+"0\" name=\"instruction_"+i+"\"><label for=\"rdc"+i+"0\">关闭</label></div>"
    }else{
    str +="<div>第"+i+"路:<input type=\"radio\" value=\"1\" id=\"rdc"+i+"1\" name=\"instruction_"+i+"\"><label for=\"rdc"+i+"1\">开启</label> <input type=\"radio\" value=\"0\" checked=\"checked\" id=\"rdc"+i+"0\" name=\"instruction_"+i+"\"><label for=\"rdc"+i+"0\">关闭</label></div>"
    }
    });是从0路开始算的。
    那个字符串连接怎么改啊,要把i弄成i+1.
      

  4.   

    恩 把i弄成i+1
    第"+(i+1)+"路