这就是我打算做的。假设我有一个姓名列表(在 DIV 中)
<div class="person">
Mike Mulky
</div>
<div class="person">
Jenny Sun
</div>
<div class="person">
Jack Kickle
</div>
我想要一个文本框,用户可以在其中键入“Jenny”,并过滤掉其中包含“Jenny”的 DIV。
什么 JQuery 插件可以让我做到这一点?或者,如果您知道更简单的事情:) 谢谢。
最佳答案
这应该可以做到:
<input type="text" id="userInput" />
<script type="text/javascript">
$('#userInput').keypress(function(){
$('div.person').hide().filter(':contains("'+this.value+'")').show();
});
</script>
关于javascript - 如何过滤项目和显示项目,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2287255/