2013-02-19 218 views
0

它是這樣的選擇複選框選擇

$(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下拉列表中選擇值某一類的元素,並希望檢查同一指數的複選框另一類一些jQuery代碼工作 但它不是在工作的所有請幫助

+0

如果你能粘貼HTML? – Jai 2013-02-19 10:46:28

+0

\t \t \t 內容1 – Xcut 2013-02-19 10:51:09

+0

不是在這裏,你可以貼在你的崗位都相應的HTML。 – Jai 2013-02-19 10:53:15

回答

2

變化

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

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

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

仍然無法訪問class2的那些複選框.... :( – Xcut 2013-02-19 10:41:49

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);     
     } 
    }); 
}); 
+0

我的comaprison部分工作正常,其只是內部的內容如果塊不工作 – Xcut 2013-02-19 10:52:35