let str = '

新冒险

软件特色:

操作。

你需要。

难度。

软件亮点:

仔细。

注意。

顶级。

软件测评:

玩家。

画面。

总的。

';

let index = 1; // 记录序号 let reg = /

([^<]*)

/g; // 匹配

标签及其中的文字内容 str = str.replace(reg, function(match, p1) { if (index === 1) { // 第一个

标签不用加序号 index++; return match; } else { let newP = <p>${index}. ${p1}</p>; // 加上序号 index = (index % 3) + 1; // 序号加1,超过3就从1开始 return newP; } });

console.log(str);

JS代码:为HTML字符串中的`<p>`标签添加序号

原文地址: https://www.cveoy.top/t/topic/ngPa 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录