Home  >  Article  >  Web Front-end  >  JS code to add emphasis to text_javascript skills

JS code to add emphasis to text_javascript skills

WBOY
WBOYOriginal
2016-05-16 17:15:571302browse
复制代码 代码如下:

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));
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn