javascript中的replaceAll功能。
<script type="text/javascript"> document.body.oncopy = function() { if (window.clipboardData) { setTimeout(function() { var text = clipboardData.getData("text"); if (text && text.length > 300) { text = text + "/r/n/n本文来自CSDN博客,转载请标明出处:" + location.href; clipboardData.setData("text", text); } }, 100); } } </script>
请注意/Microsoft/g,就是这个小g
在本例中,我们将执行一次全局替换,每当 "Microsoft" 被找到,它就被替换为 "W3C":
<script type="text/javascript">
var str="Welcome to Microsoft! "
str=str + "We are proud to announce that Microsoft has "
str=str + "one of the largest Web Developers sites in the world."
document.write(str.replace(/Microsoft/g, "W3C"))
</script>
输出:
Welcome to W3C! We are proud to announce that W3C
has one of the largest Web Developers sites in the world.