// text I will obtained from database
textToClear = "Lorem Ipsum is simply dummy text of the printing and typesetting industry. Lorem Ipsum has been the industry's standard dummy text ever since the \"1500s\", when an unknown printer took a galley of type and scrambled it to make a type specimen book. It has survived not only five centuries, but also the leap into electronic typesetting, remaining essentially unchanged. It was popularised in the 1960s with the release of Letraset sheets containing Lorem Ipsum passages, and more recently with desktop publishing software like Aldus PageMaker including versions of Lorem Ipsum.";
textAfterClear = ""
parseTextToWords();
function parseTextToWords(){
\t // basic interpunct chars should be single elements to click
\t textToClear = textToClear.replace(/\./g, ' .');
\t textToClear = textToClear.replace(/\?/g, ' ?');
\t textToClear = textToClear.replace(/\!/g, ' !');
\t textToClear = textToClear.replace(/\,/g, ' ,');
\t textToClear = textToClear.replace(/\"/g, ' " ');
\t // removing multiple spaces for single
\t textToClear = textToClear.replace(/ +(?=)/g,'');
\t
\t var words = textToClear.split(" ");
\t // generate words with ids to change their future css
\t for (var i = 0, l = words.length; i < l; i++) {
\t \t var word = $('<span />').attr({'id':'word'+i }).html(" "+words[i]);
\t \t word.css('color','black');
\t \t $('.clearText').append(word);
\t \t
\t \t $('#word'+i).click(function() {
\t \t \t if($(this).css('color') == "rgb(0, 0, 0)"){
\t \t \t \t $(this).css('color','red');
\t \t \t }else{
\t \t \t \t $(this).css('color','black');
\t \t \t } \t \t
\t \t });
\t }
}
function removeSelected(){
\t $('.clearText').find('*').each(function() {
\t if($(this).css('color') == "rgb(0, 0, 0)"){
\t \t \t textAfterClear += $(this).html();
\t \t }
});
\t $(".clearText").html(textAfterClear);
}
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.1/jquery.min.js"></script>
<script src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"></script>
<link rel="stylesheet" href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css">
<title>Word chooser</title>
</head>
<body>
<div class="clearText" style="border: 1px solid darkorange;" >
</div>
<div align="center"><button onclick="removeSelected()" type="submit">Delete Choosed</button></div>
</body>
</html>
您可以使用任何编辑器进行此操作。我知道'ckeditor'和'quill',搜索从任何一个获得选定的文本内容,并使自己的多个下拉菜单确认删除或取消选择。 – C2486
我发现的东西,可以给你一个想法:http://jsfiddle.net/Lad1dp18/1/ –
好的,谢谢你Niklesh,我会尝试做一些奇迹这一点。 –