通过javascript给指定位置赋值

来源:互联网 发布:字符数组相减 编辑:程序博客网 时间:2024/05/18 09:09

通过javascript给指定为位置设置值

  最近有需要给html的input设置默认值,设置为当前系统时间的上一个月的最后一天,通过javascript获取了系统时间做了处理,发现没生效,原来是放置的位置有问题,这段javascript代码应该放在input的后面。
  页面处理完毕回到该页面,会返回一个值,需要把该值再次赋值给input位置。
  具体代码如下所示。

<!DOCTYPE html><html><head><title>1.html</title><meta name="content-type" content="text/html; charset=UTF-8"><script type="text/javascript">var upTime = '<%=upTime%>';//el获取后台页面传来的值upTim='2016-09'}    function init() {        var upTime="top";        if (upTime && upTime != 'null') {//判断是否为空            document.getElementById("t").value = upTime;        }    }</script></head><body onload='init()'>    <input id="t" type="text" value="fdsa" /> This is my HTML page.    <br><script type="text/javascript" >     function GetDateStr() {        var date_ = new Date();        var year = date_.getFullYear();        var month = date_.getMonth();        if(month<10) month='0'+month;        var day = new Date(year, month, 0);        return year + '-' + month ;//+ '-' + day.getDate();//当月最后一天    }  var getDate=GetDateStr();  document.getElementById("t").value=getDate;</script></body></html>                                 

0 0
原创粉丝点击