简单的jQuery代码段,用任意给定的字符串替换该位置上的所有文本。 对于根据可能发生变化的动态变量来更改公司名称可能很有用。
重要提示:不要忘记replace()函数返回一个值,并且不会在页面上进行实时更新。 为此,您只需为页面元素分配.replace()的结果即可。
//ie to replace all dots on page with hyphens
var replace_str = $('body').html().replace(/./g,'-');
$('body').html(replace_str);
//if that doesn't work try this
var strNewString = $('body').html().replace(/./g,'---');
$('body').html(strNewString);