已从数据库得到一组词 aaa,bbb,ccc, 词以逗号分开. 通过这组词如何判断下面多选框哪些是选中,并输出为选中.<input name="aaa" type="checkbox" id="aaa" value="aaa"/>aaa
<input name="bbb" type="checkbox" id="bbb" value="bbb"/>bbb
<input name="ccc" type="checkbox" id="ccc" value="ccc"/>ccc
<input name="ddd" type="checkbox" id="ddd" value="ddd"/>ddd上面的就只有前三个选中.我想可以通过词组与name对比,或者与id对比,再不行与value对比,但是我没有js基础麻烦哪位仁兄帮忙写段代码 不胜感激.

解决方案 »

  1.   


    <input name="newstype" type="checkbox" id="newstype" value="1"
     <%if InStr(NEWSTYPE,"aaa")>0 then response.write " checked " %>>
    aaa                                <input name="newstype" type="checkbox" id="newstype" value="2"
    <%if InStr(NEWSTYPE,"bbb")>0 then response.write " checked " %>>
                                    bbb                                <input name="newstype" type="checkbox"  id="newstype" value="3" 
    <%if InStr(NEWSTYPE,"ccc")>0 then response.write " checked " %>>
                                   ccc
      

  2.   

    后台判断就可以了!js:<input name="aaa" type="checkbox" id="aaa" value="aaa"/>aaa
    <input name="bbb" type="checkbox" id="bbb" value="bbb"/>bbb
    <input name="ccc" type="checkbox" id="ccc" value="ccc"/>ccc
    <input name="ddd" type="checkbox" id="ddd" value="ddd"/>dddvar v="aaa,bbb,ccc"; Array.prototype.contain=function(value){
            if(this!=null && this.length>0){
                for(var i=0;i<this.length;i++)
                {
                    if(this[i]==value){ return true;}
                }
            }
            return false;
        };  var checkedArray = v.split(',');
                        chkList = document.getElementsByTagName('input'); 
                         for(var i=0;i<chkList.length;i++) 
                           { 
                               if(chkList[i].type=='checkbox')
                                {   
                                     chkList[i].checked=checkedArray.contain(chkList[i].value);
                                } 
                             }
      

  3.   

    楼上老胡
    新建一个html这样写<script language="javascript">
    var v="aaa,bbb,ccc,";
    Array.prototype.contain=function(value){
      if(this!=null && this.length>0){
      for(var i=0;i<this.length;i++)
      {
      if(this[i]==value){ return true;}
      }
      }
      return false;
      };  var checkedArray = v.split(',');
      chkList = document.getElementsByTagName('input');  
      for(var i=0;i<chkList.length;i++)  
      {  
      if(chkList[i].type=='checkbox')
      {   
      chkList[i].checked=checkedArray.contain(chkList[i].value);
      }  
      }
    </script>
    </head>
    <body>
    <form name="addcontent" method="post" action="">
    <input name="aaa" type="checkbox" id="aaa" value="aaa"/>aaa
    <input name="bbb" type="checkbox" id="bbb" value="bbb"/>bbb
    <input name="ccc" type="checkbox" id="ccc" value="ccc"/>ccc
    <input name="ddd" type="checkbox" id="ddd" value="ddd"/>ddd
    </form>
    </body>并没有选中的效果 不知道哪里不对