У меня есть код, где пользователь может ввести некоторый текст, и когда он нажмет кнопку, текст будет вставлен ниже на страницу для последующего использования.
Но прежде чем перейти туда, я быхотел бы сделать некоторые числа нижними или верхними, если они набирают «_» или «^» перед числом.
Мой код выглядит примерно так:
function moveText() {
var string = document.getElementById("input").value;
var node = document.createTextNode(string);
var para = document.createElement("p");
para.appendChild(node);
var element = document.getElementById("output");
element.appendChild(para);
}
<! DOCTYPE HTML >
<body>
<div>
<!-- I have included an example of what a user might write -->
<input type="text" id="input" value="1 _2 3 _4 ^5">
<input type="button" value="insert" onclick="moveText()">
</div>
<div id="output">
<!-- This is where the text goes when the button is pressed -->
<!-- When the text goes here I'd like all numbers following a "_" to be subscript and "^" to be supscript -->
</div>
</body>
Есть идеи?Заранее спасибо