站长资源网络编程
给文字加上着重号的JS代码
简介复制代码 代码如下:var s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890';function f(s, width){ return s.replace( new RegExp('[\\s\\S]{1,'+(width || 4)+'}', 'g'),
复制代码 代码如下:
var s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890';
function f(s, width){
return s.replace(
new RegExp('[\\s\\S]{1,'+(width || 4)+'}', 'g'),
function(m){
return '^' + new Array(m.length).join(' ');
});
}
console.log(s);
console.log(f(s, 4));
console.log(f(s, 8));
var s = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ01234567890';
function f(s, width){
return s.replace(
new RegExp('[\\s\\S]{1,'+(width || 4)+'}', 'g'),
function(m){
return '^' + new Array(m.length).join(' ');
});
}
console.log(s);
console.log(f(s, 4));
console.log(f(s, 8));
上一篇:判定是否原生方法的JS代码