document.write 问题

来源:百度知道 编辑:UC知道 时间:2024/07/02 04:27:30
<script >
function addsth(){
document.write("<input type=text name=text1>");
}
</script>
<html>
<head>
<title>test</title>
<meta http-equiv="content-script-type" content="text/javascript">
</head>
<input type=button onclick=addsth() value='hit me'>
</html>

代码如上面所示,我想要点击按钮"hit me"后加载一个文本框"text1",但点击后按钮控件"hit me"却不见了。这是为什么呢,有没有办法在点击按钮后"hit me"也能加载。
一楼的,谢谢了,但是怎么看不见文本框了……

使用
var em=document.createElement('input');
em.type='text';
em.name='text1';
document.appendChild(em);

是document.body.appendChild(em);
刚开始写错了

document.write("<input type=text name=text1>");

就是页面的输出了, 你看里面哪里还有 input