选择下拉列表中的复选框

时间:2013-02-19 10:30:55

标签: jquery

处理一些Jquery代码就像这样

 $(function(){
     $("select").change(function() {                
         $(".class1").each(function(index) {                                
             if($("select option:selected").text()== $(this).text()) {
                  $(".class2:eq(index)").prop('checked', true);                 
             }  
         })
     })
 })

<INPUT TYPE="CheckBox" CLASS='class2'> 
<TD CLASS=class1>content1</TD>

我想将下拉列表中的选定值comapre到某个类的元素,并希望检查另一个类中相同索引的复选框 但它根本不起作用请帮助

2 个答案:

答案 0 :(得分:2)

更改

$(".class2:eq(index)").prop('checked', true);   

$(".class2:eq("+index+")").prop('checked', true); 

$(".class2").eq(index).prop('checked', true); 

答案 1 :(得分:1)

即使你可以试试这个:

 $(".class2").index(index).prop('checked', true);  

更多编辑:

$("select").change(function() {
     var selText = $("option:selected", this).text(); // <--get the text here
     $(".class1").each(function(index) {                                
         if(selText== $(this).text()) {  //<---then compare here
              $(".class2").eq(index).prop('checked', true);                 
         }  
     });
 });