[英]filter radiobuttonlist with letters typed in textbox
I want to filter mycheckbox list with letters typed in textbox. 我想用文本框中输入的字母过滤mycheckbox列表。 My checkboxlist get datafrom database. 我的checkboxlist从数据库中获取数据。 Here what I tried with javascript but it's not working. 这是我尝试使用javascript,但它不起作用。 Is there any way to do like. 有什么办法可以做的。
<asp:TextBox ID="locationFilter" placeholder="Search Area" CssClass="locator filter-text" runat="server"></asp:TextBox>
<asp:RadioButtonList ID="areasList" ClientIDMode="Static" autocomplete="off" CssClass="mark" AutoPostBack="true" runat="server" RepeatLayout="Flow">
</asp:RadioButtonList>
<script>
$(function() {
$('#locationFilter').on('keyup', function() {
var query = this.value;
$('[id^="areasList"]').each(function(i, elem) {
if (elem.value.indexOf(query) != -1) {
$(this).closest('label').show();
}else{
$(this).closest('label').hide();
}
});
});
});
</script>
TextBox will have different id in the browser because its server control. TextBox在浏览器中具有不同的ID,因为它的服务器控制。 Here is working script: 这是工作脚本:
<script>
$(function () {
$('input[id $= "locationFilter"]').on('keyup', function () {
var query = this.value;
$('input[id ^= "areasList"]').each(function (i, elem) {
var radioButton = $(this);
var show = radioButton.val().indexOf(query) != -1;
radioButton.toggle(show);
var label = radioButton.next('label');
label.toggle(show);
label.next('br').toggle(show);
});
});
});
</script>
Change to below, 改为以下,
$(function () {
$('#locationFilter').on('keyup', function () {
var query = this.value;
$('#areasList input[type=radio]').each(function (i, elem) {
if (elem.value.indexOf(query) != -1) {
$(this).show();
$(this).next('label').show();
} else {
$(this).hide();
$(this).next('label').hide();
}
});
});
});
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.