我有一个像这样的字符串:
var report = 'Verifying Wireless Interface is present and state is Disconnected:PASSED<br>Verify Profile not present on the Client:PASSED<br>Add Profile to the Client:PASSED<br>Verify Profile Added Present on the Client:PASSED<br>Connecting to Access Point:PASSED<br>Verify the State is Connected:PASSED<br>Disconnecting from Access Point:PASSED<br>Verify the State is Disconnected:PASSED<br>ReConnecting to Access Point:PASSED<br>Verify the State is Connected:PASSED<br>Verify Ping to the Gateway (Access point):PASSED<br>Verify Signal Strength Greater than 75%:PASSED<br>Verify Round Trip Time not greater than 30 millieseconds:PASSED<br>Disconnecting from Access Point:PASSED<br>Verify the State is Disconnected:PASSED<br>Delete Profile to the Client:PASSED<br>Verify Profile Not Present on the Client:Failed<br>';
Run Code Online (Sandbox Code Playgroud)
由此,我必须为PASSED字符串设置绿色,为字符串设置红色Failed.怎么可能......
你需要将这些单词包装在另一个元素中
report = report.replace(/:PASSED/g, ':<span class="passed">PASSED</span>').replace(/:Failed/g, ':<span class="failed">Failed</span>');
Run Code Online (Sandbox Code Playgroud)
然后
.passed {
color:green
}
.failed {
color:red;
}
Run Code Online (Sandbox Code Playgroud)
演示:小提琴