本帖最后由 ask00000001 于 2011-10-21 09:26:08 编辑

解决方案 »

  1.   


    这样写呢?
    var p = ["picValue","..."]for(var i= 0;i<p.length;i++){
    var objname = ":radio[name='"+p[0]+"']:first";
    $(objname).attr("checked",true);
    }
      

  2.   

    var p = ["picValue","..."]for(var i= 0;i<p.length;i++){$(":radio[name='"+p[i]+"']:first").attr("checked",true);
    }
      

  3.   

    这个貌似用 eval()处理可以
      

  4.   


    $(function(){

    var arr = ["picValue","gpsValue"];
    for(var i=0;i<arr.length;i++){

    $(":checkbox:#'"+arr[i]+"'").click(function() {
    //这里以前的写法是$(":checkbox:#picValue")
    if($(this).attr("checked") == false){

    $(":radio[name='"+arr[i]+"']").attr("checked",false);

    }else{
    $(":radio[name='picValue']:first").attr("checked",true);
    //这里的picValue我想用arr[0]替换
    }
    });
    }
    });
    是这样的!
      

  5.   

    $(":checkbox:#'"+arr[i]+"'")
    ==》
    $("#"+arr[i])完毕
      

  6.   

    把  $(":radio[name='picValue']:first").attr("checked",true);中的picValue用arr[i]替换该如何替换 $(":radio[name='"+arr[i]+"']").attr("checked",true);上面这种方式不正确,请给出正确的方式
      

  7.   


    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">
    <html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gbk">
    <title>Untitled Document</title>
    <script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.6.4/jquery.min.js"></script>
    <script type="text/javascript">
    //radio的值
    var radio_value = 'loveu';
    //checkbox的值,缺少is_3
    var checkbox_value = new Array("is_1","is_2","is_4","is_5","is_6");
    $(function(){
    //首先,这个radio每次只能选择一个
    $(":radio[name='"+radio_value+"']:first").attr("checked",true);
    //checkbox的选择
    $.each(checkbox_value,function(index,el){
    $(":checkbox[name='"+el+"']:first").attr("checked",true);
    });
    });
    </script>
    </head>
    <body>
    <br>
    <input type="radio" name="love" value="01">爱
    <input type="radio" name="love" value="02">不爱
    <input type="radio" name="love" value="03">可以爱
    <input type="radio" name="love" value="04">还是爱
    <input type="radio" name="love" value="05">最终爱
    <input type="radio" name="love" value="06">不得爱
    <br>
    <input type="radio" name="loveu" value="01">爱u
    <input type="radio" name="loveu" value="02">不爱u
    <input type="radio" name="loveu" value="03">可以爱u
    <input type="radio" name="loveu" value="04">还是爱u
    <input type="radio" name="loveu" value="05">最终爱u
    <input type="radio" name="loveu" value="06">不得爱u
    <br>
    <input type="checkbox" name="is_1" value="01">爱u
    <input type="checkbox" name="is_2" value="02">不爱u
    <input type="checkbox" name="is_3" value="03">可以爱u
    <input type="checkbox" name="is_4" value="04">还是爱u
    <input type="checkbox" name="is_5" value="05">最终爱u
    <input type="checkbox" name="is_6" value="06">不得爱u
    </body>
    </html>
      

  8.   

    $(":checkbox[name='"+el+"']").attr("checked",true);
    去掉:first就行,这里没必要用
      

  9.   

    楼主是不是把p[i]写成p[0]了?
      

  10.   


    <html>
    <head>
    <title>测试JavaScript</title>
    <script type="text/javascript" src="jquery-1.6.1.js"></script>
    <script type="text/javascript">
    $(function(){           
                var arr = ["picValue","gpsValue"];
                for(var i=0;i<arr.length;i++){             
                    $("#"+arr[i]+":checkbox").click(function() {
                    if(!$(this).attr("checked")){
                        $(":radio[name='"+this.id+"']").attr("checked",false);
                        
                    }else{
                        $(":radio[name='"+ arr[0] + "']").attr("checked",true);
                        //这里的picValue我想用arr[0]替换
                    }
                    });
                }
        }); </script>
    </head>
    <body>
       <input type="checkbox" id="picValue" />
       <input type="checkbox" id="gpsValue" />
    <input type="radio" name="picValue" />
    <input type="radio" name="gpsValue" />
    </body>
    </html>这样呢?
      

  11.   

    var p = ["picTest","..."]
    $(":radio:#'"+p[0]+"':first").attr("checked",true)
      

  12.   


     $(function() {
                    var p = ['Rd0', 'Rd1'];
                    for (var i = 0; i < p.length; i++) {
                        $(":radio[name='" + p[i] + "']:first").attr('checked', 'checked');
                    }
                })
      

  13.   

    没有问题吧.
    <html><head>
    <script type="text/javascript" src="jquery/jquery.js"></script>
    <script type="text/javascript">
    $(document).ready(function(){
      $(":button").click(function(){
         var p = ["a1","a2","a3"] for(var i= 0;i<p.length;i++){    $(":radio[name='"+p[i]+"']").attr("checked",true);
    }  });
    });
    </script>
    </head><body>
    <p>If you click on me, I will disappear.</p>
    <input type='radio' name='a1' >a1<br>
    <input type='radio' name='a2' >a1<br>
    <input type='radio' name='a3' >a1<br>
    <button>choose</button>
    </body></html>