使用jquery删除包含的行

Remove Lines Containing using jquery

本文关键字:包含 删除 jquery 使用      更新时间:2023-09-26

我想使用jquery创建Remove Lines Containing,这是我的代码:

<body>
Search lines for:
<input type="text" id="search-lines" value="Sometimes|relevance|understand" style="width:100%; margin-top:10px;" />
<button id="process">Process!</button>
<textarea id="input" style="width:100%; margin-top:10px; height:150px; resize:none;" wrap="off">Sometimes to understand a word's
meaning you need more than a definition.
At Your Dictionary we try to give you all of the tools
you need to really understand what the word means.
Seeing the word in a sentence can
provide more context and relevance.</textarea>
<textarea id="containing-output" rows="4" style="width:100%; margin-top:10px; height:150px; resize:none;" wrap="off"></textarea>
<textarea id="not-contating-output" rows="4" style="width:100%; margin-top:10px; height:150px; resize:none;" wrap="off"></textarea>
</body>

这就是它的工作原理:

搜索行:

有时|相关性|理解

文本行输入:

有时理解单词的

这意味着你需要的不仅仅是一个定义。

在你的字典,我们试图给你所有的工具

你需要真正理解这个词的意思。

看到句子中的单词可以

提供更多上下文和相关性

包含行输出:

有时理解单词的

你需要真正理解这个词的意思。

提供更多上下文和相关性

不包含行输出:

这意味着你需要的不仅仅是一个定义。

在你的字典,我们试图给你所有的工具

看到句子中的单词可以

您可以使用数组

var unwantedwords= array(
//create an array of your list of words
)

var sometext="有时理解一个单词的";//这是你的字符串

然后循环遍历数组,检查这些值,并将其从字符串中删除

for (index = 0; index < unwantedwords.length; ++index) {
var word = unwantedwords[index ];
var check = sometext.indexOf(word)
  if(check !== false)
   {
     removedwordstring = sometext.replace(word,'');
   }
}

这个怎么样?

$(document).ready(function () {
    $("#process").click(function(){
    var searchCriteria = $("#search-lines").val().split("|");
      // You can split with 'n or .
    var data = $('#input').val().split("'n");
    var matched = [];
    var unMatched = [];
    $.each(data, function (i, j) {
        $.each(searchCriteria, function (index, value) {
            if (j.indexOf(value) > 0) {
                matched.push(j.replace(value, "<b>" + value + "</b>"));
            } else {
                unMatched.push(j);
            }
        });
    });
    $("#containing-output").val(matched);
    $("#not-contating-output").val(unMatched);
});
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<body>
Search lines for:
<input type="text" id="search-lines" value="Sometimes|relevance|understand" style="width:100%; margin-top:10px;" />
<button id="process">Process!</button>
<textarea id="input" style="width:100%; margin-top:10px; height:150px; resize:none;" wrap="off">Sometimes to understand a word's
meaning you need more than a definition.
At Your Dictionary we try to give you all of the tools
you need to really understand what the word means.
Seeing the word in a sentence can
provide more context and relevance.</textarea>
<textarea id="containing-output" rows="4" style="width:100%; margin-top:10px; height:150px; resize:none;" wrap="off"></textarea>
<textarea id="not-contating-output" rows="4" style="width:100%; margin-top:10px; height:150px; resize:none;" wrap="off"></textarea>
</body>