表单中的value如何得到js获取的当前时间

weihui19830914 2011-12-04 02:24:55
<input type="hidden" name="shijian" id="shijian" style="width:250px" class="intxt" value="">

我这里的表单如何获取当前js获取的时间

<script language="JavaScript"> 
function getDate()
{
var today = new Date();
var date;
date = (today.getFullYear()) +"年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日-" + today.toLocaleTimeString();
return date;
}
</script>
...全文
446 6 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
6 条回复
切换为时间正序
请发表友善的回复…
发表回复
1988_1989 2011-12-04
  • 打赏
  • 举报
回复
正解,正解。。。。
[Quote=引用 2 楼 mubeibei 的回复:]
HTML code
<input type="hidden" name="shijian" id="shijian" style="width:250px" class="intxt" value="">
<script language="JavaScript">
function getDate()
{
var today = new Date();
var date;
……
[/Quote]
Legend1988 2011-12-04
  • 打赏
  • 举报
回复
+1.[Quote=引用 3 楼 axiheyhey 的回复:]

HTML code
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
<form>
……
[/Quote]
峭沙 2011-12-04
  • 打赏
  • 举报
回复
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>Test</title>
</head>
<body>
<form>
<input type="text" id="shijian" style="width:250px" value="" />
</form>
<script>
function getDate(){
var today = new Date();
var date;
date = (today.getFullYear()) +"年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日-" + today.toLocaleTimeString();
return date;
}
window.onload = function(){
var input = document.getElementById("shijian");
setInterval(function(){
input.value = getDate();
}, 1000);
}
</script>
</body>
</html>
MuBeiBei 2011-12-04
  • 打赏
  • 举报
回复
<input type="hidden" name="shijian" id="shijian" style="width:250px" class="intxt" value="">
<script language="JavaScript">
function getDate()
{
var today = new Date();
var date;
date = (today.getFullYear()) +"年" + (today.getMonth() + 1 ) + "月" + today.getDate() + "日-" + today.toLocaleTimeString();
return date;
}
window.onload = function(){
document.getElementById('shijian').value = getDate();
};
</script>
一只老菜鸟 2011-12-04
  • 打赏
  • 举报
回复
只能通过js传入表单中,而表单自己是不能获取到的。

document.getElementById('shijian').value = getDate();

87,997

社区成员

发帖
与我相关
我的任务
社区描述
Web 开发 JavaScript
社区管理员
  • JavaScript
  • 无·法
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧