我想创建使用jquery删除行包含,这是我的代码:
<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>
这是它的工作原理:
搜索行:
有时 |的相关性 |的理解
文字行输入:
有时了解单词
。意味着您需要的不仅仅是定义。
在您的词典中,我们会尝试为您提供所有工具
你需要真正理解这个词的含义。
在句子中看到这个词可以
提供更多背景信息和相关性。
包含行输出:
有时了解单词
。你需要真正理解这个词的含义。
提供更多背景信息和相关性。
不包含行输出:
意味着您需要的不仅仅是定义。
在您的词典中,我们会尝试为您提供所有工具
在句子中看到这个词可以
答案 0 :(得分:0)
您可以使用数组
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,'');
}
}
答案 1 :(得分:0)
这个怎么样?
$(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);
});
});
&#13;
<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>
&#13;