客户端搜索复选框值
Client-side searching in checkbox value
我需要帮助。。现在我正在尝试创建一个客户端搜索,但我不知道如何比较输入文本和复选框中的值。
jsFiddle示例
示例:
jQuery("#searchBox").on("keyup paste", function() {
var value = jQuery(this).val().toUpperCase();
var rows = jQuery(".sp_country");
rows.hide();
if(value === '') {
rows.show();
return false;
}
//need something here to compare values on checkboxes and show does checkedbox who match
});
这是我位于的复选框
<span class="sp_country">
<input class="cp_country" style="cursor:pointer; display:none;" type="checkbox" name="country" value="Afghanistan"> Afghanistan
</span>
您可以使用.filter()
方法:
rows.filter(function() {
return $(this).text().toUpperCase().indexOf(value) > -1;
}).show();
或者,如果您想将输入与复选框的值进行比较:
rows.filter(function(){
return this.children[0].value.toUpperCase().indexOf(value) > -1;
}).show();
您也可以使用jQuery的.find()
方法来选择输入子体。
试试这个
$("cp_country").each(function(){
if($(this).val()==("#searchBox").val()){
$(this).parent(".sp_country").show();
}
});
整个想法是:
iterate through each of the checkbox value
if the value matches with search box value then
show the parent span element
试试这个:
$("#searchBox").on("keyup paste", function() {
var value = $(this).val().toUpperCase();
var rows = $(".cp_country");
rows.hide();
if(value === '') {
rows.show();
return false;
}
else{
rows.each(function(){
if($(this).val().toUpperCase().indexOf(value) != -1){
$(this).show();
}
else{ $(this).hide();}
});
}
});
相关文章:
- 如何在angularJS中编辑时,如果DB中的值为true,则设置复选框,如果值为false,则取消选中复选框
- 如何将从谷歌自定义搜索API获取的数据放入复选框列表
- 在表中搜索相同的日期,并在td中添加复选框
- Wordpress:提交后,我如何在搜索表单中保留市场复选框
- jQuery可搜索复选框列表和三态复选框
- 客户端搜索复选框值
- 使用数据库中文本框内的复选框自动搜索
- 在 AngularJS 中添加复选框以进行搜索
- 代码点火器 - jQuery 数据表 搜索和分页时不会保留复选框中的选中值
- 角度ng重复过滤器在搜索后取消选中所有复选框
- 为复选框列表 - 动态响应列表创建一个过滤器搜索框
- 使用复选框 php 过滤搜索
- 如何重置复选框、搜索文本框和选择列表
- 使用在文本框中输入的文本搜索复选框中的项
- 简单的方法做谷歌搜索输入文本和复选框
- 元搜索-帮助Jquery ajax请求当复选框被按下
- 使用Javascript中的复选框搜索文本框
- 选中复选框时更改搜索结果
- 搜索和复选框上的角度过滤器
- 合并2个搜索表单到1个输入,加上复选框