在下面的脚本,我想强调所有的单词在句子建议改善脚本
function SearchQueue(text)
{
if(text !== null)
{
text = text.replace(/“/g, "\"");
text = text.replace(/”/g, "\"");
text = text.replace(/’/g, "\'");
text = text.replace(/‘/g, "\'");
text = text.replace(/–/g, "\-");
text = text.replace(/ +(?=)/g,'');
$.trim(text);
text = text.replace(/\d\.\s+|[a-z]\)\s+|•\s+|[A-Z]\.\s+|[IVX]+\.\s+/g, "");
text = text.replace(/([0-9A-Z]+[.)]|•)\s+/gi, "");
text = text.replace(/(\r\n|\n|\r)/gm," ");
}
var words = text.split(' ');
for(var i=0;i<words.length;i++)
$('*').highlight(''+words[i]+''); // Will highlight the script with background color
}
但是,这使我的页面“反应迟钝”。请建议我改进脚本...
多少字呢?而且,空串不是必需的。 – Ryan
计数会很高... – Exception
'/ +(?=)/'的含义是什么?一个或多个空间后跟一个空格?你可以用'/ + /'来简化它,并用一个空格代替。 –