js 输出内容 怎么显示在当前页面

JavaScript011

js 输出内容 怎么显示在当前页面,第1张

<html>

<head>

<script type="text/javascript">

function page_onload(){

document.getElementById("name").value = "XXX小明"

}

</script>

</head>

<body onload="page_onload()">

<input id="name" name="name" type="text" value="" />

</body>

</html>

将id为name选框设置为:XXX小明

自己把这段代码在浏览器上运行一下,就明白了。

你查查document.write是什么意思,如果使用不合理它会把当前页面清空然后再输出,所以才会出现select标签不见了。

一般的话,只有在页面加载的时候才会使用document.write这个函数,如果你在方法中调用这个方法,由于此时的document已经加载而且分析完了,那么document.write()将会重新加载document,而且在加载之前它会把以前加载的东西清除掉。这就是问什么你的select标签不见得原因。

对于你的程序你可以把要加载的东西用innerHTML输出到一个div中,这样的话就没有问题了,而且也比较的规范。

我想把这个URL 输出到

以下代码中的(当前页URL)

可以这样:

var url=window.location.href

document.writeln(" <form action=\"{fy:dir}user\/Checklogin.asp?Action=LoginCheck&oldurl="+url+"\" method=\"post\" class=\"simform ulogin\">")