选择复选框选择
问题描述:
它是这样的选择复选框选择
$(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代码工作 但它不是在工作的所有请帮助
答
变化
$(".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
答
甚至你可以试试这个:
$(".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
我的coma*部分工作正常,其只是内部的内容如果块不工作 – Xcut 2013-02-19 10:52:35
如果你能粘贴HTML? – Jai 2013-02-19 10:46:28
\t \t \t
不是在这里,你可以贴在你的岗位都相应的HTML。 – Jai 2013-02-19 10:53:15