How to change the text color in a string in javascript
巴扎黑
巴扎黑 2017-05-19 10:32:03
0
3
829
  1. 'Test text test text test text cough word test text test text cough test text test text test text test text cough word test text '

  2. The above text test is used to know the position of the first and third cough text and how to change the color of these two words.

 <textarea class="editor-input" placeholder="请输入内容" v-model="inputValue"></textarea>
<iframe src="about:blank" id="bbb" contentEditable="true" width="100%" height="100%"></iframe>

Currently using this method to solve

巴扎黑
巴扎黑

reply all(3)
PHPzhong
测试文字<span style="color:red">测试文字</span>
为情所困

The following replaces the first and third coughs, adding red.

var str = '测试文字测试文字测试文咳嗽字测试文字测试文字咳嗽测试文字测试文字测试文字测试文咳嗽字测试文字';

var result = str.replace(/(咳嗽)([^咳]+[^咳]+)/, '<span sytle="color:red"></span><span sytle="color:red"></span>');

console.log(result);
大家讲道理

If you know the location, just subscript and add color. You can also use regular filtering

Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!