jsp用js设置文本框的值

我在jsp页面用javascript写了一个函数就是返回系统当前时间,而且隔1秒刷新一次,我该怎么把这个值放到文本框中去,
我在javascript的函数里面写了:document.myform.sj.value=time;
sj是我的文本框,time是时间;我是把这一句放到javascript函数里面的

在仔细阅读了你的问题后,帮你写了一个,不知道符合你的要求不。

我用html+js写的,关于后台的变量的接收由你自己完成。

html代码(复制到记事本后另存为以.html为后缀的文件,再到浏览器中打开看效果):

<html><head>
<script language="javascript">
function countAll(o){
var sum=0;
for(var i=1;i<=3;i++){
eval("if(o.c" + i + ".checked)sum+=o.j"+i+".value*o.s"+i+".value;");
}
o.zong.value=sum;
}</script>
</head><body>
<table cellspacing="0" cellpadding="0" border="1px" bordercolor="#0033FF" bordercolordark="#FFFF00" style="margin:1px;padding:1px;text-align:center;font:12px;word-wrap:normal;word-break:keep-all;overflow:visible;" align="center">
<form action="" method="get">
<tr>
<td width="95" rowspan="2"><input name="c1" type="checkbox" id="c1" value="1">
物品1</td>
<td width="319">价格:
<input name="j1" type="text" id="j1" readonly value="20"></td>
</tr>
<tr>
<td>数量:
<input name="s1" type="text" id="s1"></td>
</tr>
<tr>
<td rowspan="2"><input name="c2" type="checkbox" id="c2" value="1">
物品2</td>
<td>价格:
<input name="j2" type="text" id="j2" readonly value="50"></td>
</tr>
<tr>
<td>数量:
<input name="s2" type="text" id="s2"></td>
</tr>

<tr>
<td rowspan="2"><input name="c3" type="checkbox" id="c3" value="1">
物品3</td>
<td>价格:
<input name="j3" type="text" id="j3" readonly value="10"></td>
</tr>
<tr>
<td>数量:
<input name="s3" type="text" id="s3"></td>
</tr>
<tr>
<td><input name="count" type="button" value="计算总价" onclick="countAll(this.form)"></td><td>总价:<input name="zong" type="text" id="zong"></td></tr><tr><td colspan="2"><input name="submit" type="submit" id="submit" value="提交"> <input name="reset" type="reset" id="reset" value="重置"></td>
</tr></tr></form></table>
</body></html>
温馨提示:内容为网友见解,仅供参考
第1个回答  2013-08-11
特地的给你写了一个
<html>
<head>

</head>
<body>
<form id="form1" action="" method="post">
<input id="sj" type="text" value="" />
</form>
<script language="javascript" type="text/javascript">
function shijian(){
var D=new Date();
var yy=D.getFullYear();
var mm=D.getMonth()+1;
var dd=D.getDate();
var h=D.getHours();
var m=D.getMinutes();
var s=D.getSeconds();
var time=yy+"-"+mm+"-"+dd+" "+h+":"+m+":"+s;
document.getElementById("sj").value=time;
setTimeout("shijian()",1000);
}
shijian();
</script>
</body>
</html>
第2个回答  2013-08-11
document.getElementById("sj").value=time;
相似回答