[英]How can insert some text in HTML without clear the page?
I want to create some textfield by script,but how can I add some text between the textfield? 我想通过脚本创建一些文本字段,但是如何在文本字段之间添加一些文本呢? I try to use "document.write" but it 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);
Well you can create a span or paragraph element and use that to hold your text inbetween the two text boxes: 好了,您可以创建一个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.