使用jquery删除包含的行
Remove Lines Containing using jquery
我想使用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>
相关文章:
- 如何删除包含内容可编辑跨度的整个跨度元素
- 删除javascript中包含特定单词的行
- 在添加或删除之前,正在使用检查classList是否包含类
- 使用jquery删除包含的行
- 如何从包含字符串的对象中删除引号
- 如何删除包含特定子项的 li
- Javascript:从数组中删除包含带有侦听器的对象的项目的最佳方法
- 对于包含特定字符串的每个元素,删除字符串及其后的所有内容
- 如果el包含此文本,请从中删除此字符串
- 如何删除包含包含某些数据的单元格的表行
- 正在Jquery中的列表中不包含任何元素的列表中删除
- 对于列表中包含带文本的跨度的每个li,请从该li中删除另一个跨度
- 通过JavaScript或jQuery删除P标记,其中包含不间断的空格
- 删除HTML脚本标记会对它所包含的JavaScript产生任何影响吗
- 删除HTML标签中包含的文本
- 从页面中删除除数组中包含的元素及其父元素/子元素之外的所有元素
- 删除一个元素,如果它包含某些内容,请使用 GreaseMonkey 中的 jQuery
- AngularJS - 如果包含字符串,则删除ng重复项
- Jquery包含删除某些字符
- 我有一个表在引导-我怎么能添加一个列,其中包含删除按钮选定行