根据文本字段中的用户输入隐藏/显示复选框
Hide/show checkboxes based on user input in text field
您可以在此处查看我当前的html/css/jshttps://jsfiddle.net/cu0cvem2/.当我有实际内容时,"组"(复选框列表)会长很多。我需要用户能够开始在输入字段中键入内容,并缩小可用的复选框。例如,如果他们开始键入"grou",那么所有复选框都将仍然存在,因为它们都包含"group"。如果开始键入"酷",他们将只剩下一个复选框"酷组"可供选择。
我希望能够将此代码添加到我用来隐藏和显示复选框的当前对象中,复选框如下所示:
StoryGroup = {
groupInput: '.story-group-container input[type="text"]',
container: '.checkbox-container',
submit: '.checkbox-container .filter',
body: 'body',
init: function() {
$(this.groupInput).click(this.showForm.bind(this));
$(this.body).click(this.hideForm.bind(this));
},
showForm: function(e) {
e.stopPropagation();
$(this.container).show();
},
hideForm: function(e) {
if (!($(e.target).is(this.groupInput) || $(e.target).is(this.container + "," + this.container + " *"))) {
$(this.container).hide();
}
}
}
我认为您需要使用keyup
事件来筛选结果。。
检查这个jsfiddle
StoryGroup = {
groupInput: '.story-group-container input[type="text"]',
container: '.checkbox-container',
submit: '.checkbox-container .filter',
body: 'body',
init: function() {
$(this.groupInput)
.click(this.showForm.bind(this))
.keyup(this.onKeyup.bind(this));
$(this.body).click(this.hideForm.bind(this));
},
showForm: function(e) {
e.stopPropagation();
$(this.container).show();
},
hideForm: function(e) {
if (!($(e.target).is(this.groupInput) || $(e.target).is(this.container + "," + this.container + " *"))) {
$(this.container).hide();
}
},
onKeyup: function(e) {
var text = $(this.groupInput).val().toLowerCase();
$(this.container)
.find(".checkbox")
.hide()
.filter(function() {
return this.innerText.toLowerCase().indexOf(text) > -1;
}).show();
}
}
StoryGroup.init();
相关文章:
- 单击其他元素或鼠标向上时隐藏输入框,但保留一次焦点
- jquery可以't隐藏输入名称为“”的表单;风格”;
- 默认情况下,在ipython笔记本中隐藏输入单元格
- 单击表单1中的按钮:更改表单2中隐藏输入的值(纯javascript)
- 如何使用 JavaScriptJQuery 将隐藏输入标签的值与选择标签的选定选项的值进行设置
- 将两个隐藏输入与简单的 JavaScript 进行比较失败
- getElementById().value未设置隐藏输入
- 为什么在下面的场景中,用于存储所选文件名和文件路径的隐藏输入字段没有在表单上生成
- 在隐藏输入上使用jQuery触发按键事件
- 使用HTML和Javascript,使用4个单选按钮显示和隐藏输入字段
- 修改隐藏输入中的json数组
- 为选中的每个复选框创建隐藏输入
- 使用数据中的值填充隐藏输入
- 将隐藏输入类型转移到我的隐藏模态/表单
- 带有隐藏输入的有序列表
- Angularjs隐藏输入字段中的文本
- 在同一页面上使用jQuery Mobile Flip Switch切换具有隐藏输入样式的图像
- 通过jQuery将动态生成的输入值传递到隐藏输入中
- 无法使用jQuery更改隐藏输入文本框的值
- HTMLJavascript-如何向输入语句添加函数并隐藏输入语句,除非选中“是”,然后取消隐藏