實(shí)現(xiàn)工商信息變更樣式
效果圖:

js_text_diff.png
function diff(){
let oldStr = '技術(shù)開發(fā)、技術(shù)推廣、技術(shù)咨詢、技術(shù)服務(wù);軟件開發(fā);組織文化藝術(shù)交流活動(dòng)(不含演出);承辦展覽展示;銷售新鮮蔬菜、新鮮水果、文化用品、工藝品、日用品、廚房用具;零售電子產(chǎn)品。依法須經(jīng)批準(zhǔn)的項(xiàng)目,經(jīng)相關(guān)部門批準(zhǔn)后依批準(zhǔn)的內(nèi)容開展經(jīng)營(yíng)活動(dòng)。'
let newStr = '銷售食品。技術(shù)開發(fā)、技術(shù)推廣、技術(shù)咨詢、技術(shù)服務(wù);軟件開發(fā);組織文化藝術(shù)交流活動(dòng)(不含演出);承辦展覽展示;銷售文化用品、工藝品、日用品、廚房用具、銷售食品以及依法須經(jīng)批準(zhǔn)的項(xiàng)目,經(jīng)相關(guān)部門批準(zhǔn)后依批準(zhǔn)的內(nèi)容開展經(jīng)營(yíng)活動(dòng)。'
// 通過(guò)符號(hào)分割成數(shù)組
let oldStrArr = oldStr.split(/[、;,。]/)
let diffNewStr = newStr
// 將完全相同的部分替換掉
for(let key of oldStrArr){
diffNewStr = diffNewStr.replace(key, '')
}
// 去除新字符串中替換掉的空字符串
let diffNewArr = diffNewStr.split(/[、;,。]/).filter(item => {return !!item})
let strWithDiff = ''
// 將新的字符串中不同的部分標(biāo)紅
for(let addStr of diffNewArr){
strWithDiff = newStr.replace(addStr, `<span style="color:red">${addStr}</span>`)
}
return strWithDiff
}