[英]How can insert some text in HTML without clear the page?
我想通過腳本創建一些文本字段,但是如何在文本字段之間添加一些文本呢? 我嘗試使用“ document.write”,但它清除了頁面。
inform = document.getElementById('addinput');
newinput = document.createElement('input');
newinput.type = "text";
newinput.name = "NumA" + i;
newinput.id = "NumA" + i;
newinput.value = a;
inform.appendChild(newinput);
add = document.write('+');
inform.appendChild(add);
newinput = document.createElement('input');
newinput.type = "text";
newinput.name = "NumB" + i;
newinput.id = "NumB" + i;
newinput.value = b;
inform.appendChild(newinput);
好了,您可以創建一個span或段落元素,並使用該元素將文本保留在兩個文本框之間:
inform = document.getElementById('addinput');
newinput = document.createElement('input');
newinput.type = "text";
newinput.name = "NumA" + i;
newinput.id = "NumA" + i;
newinput.value = a;
inform.appendChild(newinput);
add = document.createElement('span');
add.innerHTML = "+";
inform.appendChild(add);
inform.appendChild(add);
newinput = document.createElement('input');
newinput.type = "text";
newinput.name = "NumB" + i;
newinput.id = "NumB" + i;
newinput.value = b;
inform.appendChild(newinput);
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.