且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

Javascript-将字符串中的所有数字更改为下标

更新时间:2023-02-10 10:21:38

使用下面给出的简单正则表达式替换

Use a simple regex replace as given below

document.getElementById("entered").innerHTML = userIn.replace(/(\d+)/g, '<sub>$1</sub>');

演示:小提琴