Javascript - Change all numbers in a string to subscripts
问题 I have an input box in which the user inputs a chemical formula. I am displaying their input back to them in a table, with the following code in my javascript file. document.getElementById("entered").innerHTML = userIn; ...where "userIn" is the "id" of the input box, and "entered" is the id of the data in my table row. Now, here's my question: Is there any way I can change all of the numbers in the formula to subscripts, but leaving the letters unchanged? So if H2O2 is entered, only the 2's