如题:现在界面上有两个<input type="text" id="txt1"> <input type="text" id="txt2">
当打开页面时我想为两个文本框赋当前时间和当前时间的前三天的初始值 请问该怎样实现?
麻烦高手们把代码帮忙写一下记住是前台不是后台!!! 谢谢

解决方案 »

  1.   

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <script>
    function abc()
    {
    var today=new Date();
    var otherDay=new Date(today.getTime()-259200000);
    document.getElementById("txt1").value=today.toLocaleString();
    document.getElementById("txt2").value=otherDay.toLocaleString();
    }
    </script>
    </head>
    <body onload="abc()">
    <input type="text" id="txt1"/>
    <input type="text" id="txt2"/>
    </body>
    </html>
      

  2.   

    如果你要00:00:00的那种就这样写:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <script>
    function abc()
    {
    var today=new Date();
    var otherDay=new Date(today.getTime()-259200000);
    document.getElementById("txt1").value=today.toLocaleString();
    document.getElementById("txt2").value=otherDay.toLocaleString();
    }
    </script>
    </head>
    <body onload="abc()">
    <input type="text" id="txt1"/>
    <input type="text" id="txt2"/>
    </body>
    </html>
      

  3.   

    如果前三天的时间要00:00:00的那种,就这样写:
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html>
    <head>
    <script>
    function abc()
    {
    var today=new Date();
    var otherDay=new Date(today.getTime()-259200000);
    document.getElementById("txt1").value=today.toLocaleString();
    document.getElementById("txt2").value=otherDay.toLocaleString();
    }
    </script>
    </head>
    <body onload="abc()">
    <input type="text" id="txt1"/>
    <input type="text" id="txt2"/>
    </body>
    </html>