【发布时间】:2017-06-29 05:16:50
【问题描述】:
我想通过关键字匹配对大约 50 个隐藏的 div 进行排序。为了简化示例,我目前只展示了两个。该脚本非常适合英语,但是当您本地化某些单词时,它们可能包含重音,这会破坏脚本查找匹配结果的能力。示例:在西班牙语中键入 telefono 与 teléfono 不匹配。我看到了从一个字符串中删除重音的示例,但是如何从所有字符串中删除它们?
<form action="" class="styled" id="live-search" method="post">
<fieldset>
<p style="padding-left: 10px; padding-top: 5px;">Start typing to filter.</p>
<input class="text-input" id="filter" style="margin-top: -60px;" type="text" value="" />
<div id="filter-count"></div>
</fieldset>
</form>
<div>
<p class="listheaders"><strong>Phones:</strong></p>
<ul class="vglist">
<li class="listitems"><a href="/en/node/38871" target="_blank">Téléphone Android Nexus 5x<br />
<img src="someImagePathEtc" width="100" /> </a> <span style="display: none;">teléfono phone nexus 5x</span></li>
<li class="listitems"><a href="/en/node/33302" target="_blank">Einlösen von Geschenkkarten<br />
<img src="someImagePathEtc" width="100" /></a> <span style="display: none;">gift cards</span></li>
</ul>
</div>
<script>
$(document).ready(function(){
$("#filter").keyup(function(){
// Retrieve the input field text and reset the count to zero
var filter = $(this).val(), count = 0;
// Loop through the visual guide list
$(".vglist li").each(function(){
// If the list item does not contain the text phrase fade it out
if ($(this).text().search(new RegExp(filter, "i")) < 0) {
$(this).fadeOut("slow");
// Show the list item if the phrase matches and increase the count by 1
} else {
$(this).show();
count++;
}
});
// Update the count
var numberItems = count;
$("#filter-count").html(" Number of Guides: "+count);
});
});
</script>
我需要更新以下小提琴,以便它可以匹配使用我们的不带重音符号键入的字符。谢谢
【问题讨论】:
-
由于我的声誉,我无法添加评论,但您可以看到:stackoverflow.com/questions/11115417/…
标签: javascript jquery