Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/398.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 短语与jQuery的比较_Javascript_Jquery - Fatal编程技术网

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();
});