我需要使用jQuery通过复选框的TEXT搜索复选框列表项,而不是通过Value。
按值搜索代码下方
$(document).ready(function () {
$("#maincontent_txtSearchTo").on("keyup", function () {
debugger;
var g = $(this).val().toLowerCase();
$("#maincontent_chkQuestionTo tr td input").each(function () {
var s = $(this).val().toLowerCase();
$(this).parent().parent()[s.indexOf(g) !== -1 ? 'show' : 'hide']();
});
});
});
我需要它通过TEXT进行搜索。
请参阅下面生成的代码的示例
<input name="ctl00$maincontent$txtSearchTo" type="text" id="maincontent_txtSearchTo" Placeholder="Search..." />
<table id="maincontent_chkQuestionTo">
<tr>
<td><input id="maincontent_chkQuestionTo_0" type="checkbox" name="ctl00$maincontent$chkQuestionTo$0" value="2057" />
<label for="maincontent_chkQuestionTo_0">What is money in finance?</label>
</td>
</tr><tr>
<td><input id="maincontent_chkQuestionTo_1" type="checkbox" name="ctl00$maincontent$chkQuestionTo$1" value="2058" />
<label for="maincontent_chkQuestionTo_1">What is Good?</label>
</td>
</tr>
</table>
如果你能帮忙,我很感激。
非常感谢
James
我认为Text是指标签。如果是这样,则需要在标签上使用.html((。
请尝试下面的代码;
$(document).ready(function () {
$("#maincontent_txtSearch").on("keyup", function () {
debugger;
var g = $(this).val().toLowerCase();
$("#maincontent_chkQuestion tr td input").each(function () {
var td = $(this).parent();
var label = $(td).find("label");
if($(label).html().toLowerCase().indexOf(g) == -1){
$(td).parent().hide();
}else{
$(td).parent().show();
}
});
});
});