jQuery只拆分没有特定类的单词

jQuery只拆分没有特定类的单词,jquery,text,Jquery,Text,我有以下标记: <div id ="selectable1"> <span id="layer6"> here are some words that needs to be splited <span class="good">this should not be splitted<span> this should be splitted <span class="good">and this should not be spite

我有以下标记:

<div id ="selectable1">
<span id="layer6">
here are some words that needs to be splited
<span class="good">this should not be splitted<span>
this should be splitted
<span class="good">and this should not be spited<span>
</span>
</div>

下面是一些需要拆分的单词
这不应该分割
这应该分开
这是不应该吐出来的
我正在尝试编写一个函数,它将只拆分没有类“good”的单词。 我用的是:

var words = $("#selectable1 span.cica").text().split(" ");
var text = words.join("</span><span class='drag col'>  ");
$("#selectable1 span.cica").html("<span class='drag col'>" + text + "</span>");
var words=$(“#selectable1 span.cica”).text().split(“”);
var text=words.join(“”);
$(“#selectable1 span.cica”).html(“+text+”);
…但这是拆分我所有的单词,我需要“good”类不要拆分,也不要添加到var text-join中

我希望我已经很好地解释了我想在这里做什么,我知道这会让人困惑


感谢您的帮助

根据评论更新。由于您被包装在一个跨度中,选择器有点疯狂,请执行以下操作:

var span = $("#selectable1>span.cica").clone();
span.find(".good").remove();
var words = span.text().split(" ");
var text = words.join("</span><span class='drag col'>  ");
var span=$(“#selectable1>span.cica”).clone();
span.find(“.good”).remove();
var words=span.text().split(“”);
var text=words.join(“”);
var words=$(“#selectable1 span:not(.good)”).text().split(“”);
var text=words.join(“”);

这可能会奏效…

*splitted='split'。一般来说,您正在阅读
text
,然后设置
html
。如果有一个
Thanx Bobnice,我会看看我是否能做到这一点。我尝试过:var words=$(“#selectable1 span.cica:not(.good)”).text().split(“”);var text=words.join(“”)$(“#selectable1 span.cica”).html(“+text+”);但它不起作用。我对源代码进行了编辑,添加了实际执行variabiles@Mircea-什么是
.cica
?@Nick在这个可选择的容器中有几个跨度。活跃的人拥有这个类。cica。当有人单击一个span时,它会变为活动状态并获取类cicay您的代码应该可以工作,但此代码只获取所有文本,包括“good”类一:$(“#selectable1 span.cica”).html(“+text+”)@我现在明白你的意思了,我更新了答案,你现在应该准备好了。
var words = $("#selectable1 span:not(.good)").text().split(" ");
var text = words.join("</span><span class='drag col'>  ");