【发布时间】:2012-05-23 23:57:02
【问题描述】:
我如何(有效地 - 不降低计算机 [cpu] 速度)突出显示页面的特定部分?
假设我的页面是这样的:
<html>
<head>
</head>
<body>
"My generic words would be selected here" !.
<script>
//highlight code here
var textToHighlight = 'selected here" !';
//what sould I write here?
</script>
</body>
</html>
我的想法是将所有正文“克隆”到一个变量中,并通过 indexOf 找到指定文本,更改(插入带有背景色的跨度)“克隆”字符串并将“真实”正文替换为“克隆”一个。
我只是认为它没有效率。
你还有其他建议吗? (有创意:))
【问题讨论】:
标签: javascript performance highlight