您的位置:首页 > Web前端 > HTML

在html中让一个text输入框的默认日期是今天

2012-01-10 10:31 155 查看
方法一:
<form name="form1">

<input type="text" name="test">

</form>

<script language="JavaScript">

today=new Date();

form1.test.value=today.getYear()+'年'+today.getMonth()+'月'+today.getDay()+'日';

</script>

<br>
方法二:
---------------------------------------------------------------

<br>

<INPUT TYPE="text" id="myDate">

<SCRIPT LANGUAGE="JavaScript">

<!--

var now = new Date();

myDate.value=now.getYear() + "-"+ (now.getMonth()+1)+"-"+now.getDate();

//-->

</SCRIPT>

<br>

方法三:

---------------------------------------------------------------

<br>

<script language="JavaScript"><!--

function time_rota() //写当前日期的函数

{

var now = new Date();

var h = now.getFullYear();

var m = (now.getMonth() + 1>9) ? now.getMonth() + 1 : "0"+(now.getMonth() + 1);

var s = (now.getDate()>9) ? now.getDate() : "0"+now.getDate();

document.form1.Today.value = h+"年"+m+"月"+s+"日";

}

//--></script>

<body onload="time_rota()">

<form name=form1>

<input name=Today>

</form>
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: 
相关文章推荐