JavaScript/replace:修订间差异
来自康健生活
| 第26行: | 第26行: | ||
'-----undefineddefghundefined=======' | '-----undefineddefghundefined=======' | ||
</pre>}}}} | </pre>}}}} | ||
替换内容。 | |||
<syntaxhighlight lang="javascript"> | |||
_.name.replace(new RegExp(searchValue, 'gi'), function(targetKey, targetIndex, content) { | |||
return content.substring(0, targetIndex) + '<span>' + targetKey + '</span>' + content.substring(targetIndex + 1); | |||
});</syntaxhighlight> | |||