Javascript 短语与jQuery的比较
如果它们相似,我想将它们(放入标签Javascript 短语与jQuery的比较,javascript,jquery,Javascript,Jquery,如果它们相似,我想将它们(放入标签)一起比较,删除它们,并显示其他不相似的单词。但是这个代码被删除了,因为我们认为它是相似的,我该怎么办 示例: 你好 嗨 怎么 什么 你好 如何 你好吗 什么 好的 嗨 $(“span p”)。每个(函数){ $(“.remove p:包含(“+$(this.text()+”)).remove(); }); 输出为良好,以防输出为良好$你好吗?为您更新了小提琴: 尝试: <span style="display: none;"> <
)一起比较,删除它们,并显示其他不相似的单词。但是这个代码被删除了,因为我们认为它是相似的,我该怎么办
示例:
你好
嗨
怎么
什么
你好
如何
你好吗
什么
好的
嗨
$(“span p”)。每个(函数){
$(“.remove p:包含(“+$(this.text()+”)).remove();
});
输出为
良好
,以防输出为良好
$你好吗?
为您更新了小提琴:
尝试:
<span style="display: none;">
<p>hello</p>
<p>hi</p>
<p>how</p>
<p>what</p>
</span>
<div class="remove">
<p>hello</p>
<p>how</p>
<p>how are you?</p>
<p>what</p>
<p>fine</p>
<p>hi</p>
</div>
$("span p").each(function () {
$(".remove p:contains(" + $(this).text() + ")").remove();
});
var input = [];
/*
* Storing all values
* in a single array for
* a faster access
*/
$("span p").each(function () {
input.push($(this).text());
});
$(".remove p").each(function () {
var $this = $(this);
/*
* Now use the inArray utility
* function to find duplicates
*
* EDIT: Added toLowerCase() to allow
* case-insensitive matching
*/
if ($.inArray($this.text().toLowerCase(), input.toLowerCase()) !== -1) {
$this.remove();
}
});
$("span p").each(function () {
var item=$(this).text();
$(".remove p").filter(function(){return $(this).text()==item}).remove();
});