这个要配合服务器端程序,例如ASP吧:
      <input type="checkbox" name="h_game" value="1" <%if str=1 then response.write "checked"%>>
      棋牌
      <input type="checkbox" name="h_game" value="2"<%if str=2 then response.write "checked"%>>>
      游泳
      <input type="checkbox" name="h_game" value="3"<%if str=3 then response.write "checked"%>>>
      KTV

解决方案 »

  1.   

    那个数组我已经取到页面了 我是写JSP的
      

  2.   

    我这样写了没效果5555555555555 不知道你们能看懂不?arr = new Array();
    int r=0;
    for(r=0;r<str.length;r++)
     {
    %>
     arr[<%=r%>]=new Array(str[r]);
    <%
     }
    %>
    var ob = document.all.h_game;
    for(var j=0;j<ob.length;j++){
    if(ob[j].value==arr[j]){
    ob[j].checked = true;
        }
    }
      

  3.   

    var i,j;
      for(i=0;i<arr.length;i++){ 
        for(j=0;j<ob.length;j++){
          if(ob[j].value==arr[i]){
           ob[j].checked = true;
          }
       }
      

  4.   

    主要是你的数组里面的值有问题,你的代码把jsp和js夹杂在一起,肯定有问题了。服务器端的数组是不可能传到客户端的,要传也只能转换成js的数组表达式字符串,如['1','3','4'],但这样需要转换,容易出错。
    其实可以不用数组,只要传一个字符串给客户端就可以了。参见下例:
    只要把onload=改成"init('<%=你的字符串%>');"就实现了。<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
    <title>无标题文档</title>
    </head>
    <script type="text/javascript">
    function init(a){
    var ob = document.all.h_game;
    for(var j=0;j<ob.length;j++){
    if(a.indexOf(ob[j].value)!=-1){
    ob[j].checked = true;
     }
    }
    }
    </script><body onload="init('1378');">
    <input type="checkbox" name="h_game" value="1">棋牌
    <input type="checkbox" name="h_game" value="2">游泳
    <input type="checkbox" name="h_game" value="3">KTV
    <input type="checkbox" name="h_game" value="4">保龄球
    <input type="checkbox" name="h_game" value="5">中西餐
    <input type="checkbox" name="h_game" value="6">商务中心
    <input type="checkbox" name="h_game" value="7">茶秀 咖啡厅
    <input type="checkbox" name="h_game" value="8">健身房
    <input type="checkbox" name="h_game" value="9">宽带
    <input type="button" onclick="init();">
    </body>
    </html>
      

  5.   

    非常感谢 yyszh(追求完美) 大虾啊 你的方法一用就好拉,
    youbl(wolf) 的方法用了没效果 但我看着也挺正确的啊 给分~
    再次感谢你们2个人啊