jquery wordCount 中允许特殊字符和空格
我使用 jquery DynaCloud 和 wordCount 来创建动态标签云。 我有特定的术语要包含在云中(尽管每个用户的频率不同),并且某些术语是多个单词,或者具有特殊字符(“&”、“'”、“”等),例如该术语的一部分。
我用特定的 html 块来打破这些术语:
<pre><span class="tag">this isn't the last tag</span></pre>
作为示例。
wordCount 的工作方式(据我所知)是仅接受特定字符并按单词之间的空格进行分割。
我一直在尝试编辑脚本以允许所有字符(包括特殊字符),并且仅在 上中断。
然而,我所做的任何改变似乎都没有任何效果。
知道如何更改此代码以获取标签之间的所有内容并在标签上中断吗?
//accept Latin-1 basic + Latin-1 extended characters
testChar: function(c) {
return((c >= 0 && c <= 500)
|| (c >= 128 && c <= 151)
|| (c >= 160 && c <= 164)
|| (c >= 48 && c <= 57)
|| (c >= 224 && c <= 246)
|| (c >= 249 && c <= 255));
},
//split words
splitWords: function(words) {
var w = new Array(), str = '';
for(var i = 0, j = words.length; i < j; i++) {
c = words.charCodeAt(i);
if(this.testChar(c)) str += words.substring(i, i + 1);
else {
w.push(str);
str = '';
}
}
}
I'm using jquery DynaCloud with wordCount to create a dynamic tagcloud.
I have specific terms to include in the cloud (though the frequency is different for each user), and some of the terms are multiple word, or have special characters ("&", "'", " ", etc.) as part of the term.
I break the terms with specific html blocks:
<pre><span class="tag">this isn't the last tag</span></pre>
as an example.
The way wordCount works (as far as I can tell) is to accept only specific characters and to split on the spaces between words.
I've been trying to edit the script to allow all characters (including special), and only break on the <span class=tag>
.
However, it doesn't seem that any changes I make have any effect.
Any idea how to alter this code to get everything between the tags and break on the tag?
//accept Latin-1 basic + Latin-1 extended characters
testChar: function(c) {
return((c >= 0 && c <= 500)
|| (c >= 128 && c <= 151)
|| (c >= 160 && c <= 164)
|| (c >= 48 && c <= 57)
|| (c >= 224 && c <= 246)
|| (c >= 249 && c <= 255));
},
//split words
splitWords: function(words) {
var w = new Array(), str = '';
for(var i = 0, j = words.length; i < j; i++) {
c = words.charCodeAt(i);
if(this.testChar(c)) str += words.substring(i, i + 1);
else {
w.push(str);
str = '';
}
}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我最终得到了这个。
我一直在尝试使用类似于脚本原作者使用的编码字符
(因此c>=0 && c<=500)
。 但我想太多了。这一切都可以用简单的字符来完成,所以编辑它说
现在我需要的所有字符都显示出来了。
I got this eventually.
I had been trying to use encoded characters similar to what the original author of the script used
(so c>=0 && c<=500)
. but I was over thinking the problem.this can all be done with just plain chacters, so edited it to say
and now all the characters I need show up.