正如您所看到的,我是JavaScript的新手,我正在处理一个表单,当用户点击提交时知道上次更新信息时,需要发送今天的日期值。
我目前有以下代码,但似乎没有更新该字段的日期。你能帮我理解为什么吗?
<script type="text/javascript">
var datetoday = new Date();
var months = new makeArray('Jan','Feb','Mar','Apr','May','June','July','Aug','Sept','Oct','Nov','Dec');
var day = datetoday.getDate();
var month = datetoday.getMonth() + 1;
var yyyy = datetoday.getFullYear();
var my_date = day+"-"+months[month]+"-"+yyyy;
document.getElementById("DATE_TODAY").value = my_date;
</script>
&#13;
<form method="POST">
* First Name:
<input name="FNAME" type="text" />
<br>
* Last Name:
<input name="LNAME" type="text" />
<br>
* Street Address:
<input name="ADDRESS" type="text" />
<input type="hidden" name="DATE_TODAY" id="DATE_TODAY" />
</form>
&#13;
答案 0 :(得分:1)
makeArray()是一个方法而不是一个对象,因此实例化它会给你一个错误(参见api.jquery.com/jQuery.makeArray)。
只需像这样创建你的数组,它就像你想要的那样:
<root xmlns:og="http://www.example.com" xmlns:dc="http://www.example.com" >
<hits>
<hits>
<_index>indexname</_index>
<_type>indextype</_type>
<_source>
<keywords>keywords-NOT-PROVIDED</keywords>
<secureFlag>false</secureFlag>
<description>How do you make sure your search and big data applications are well-maintained? How to free IT staff's time to focus more on business goals? Watch our expert address the top 5 managed services questions asked by customers.</description>
<connectorSpecific>
<discoveredBy>http://www.example.com/enterprise-search-case-studies</discoveredBy>
<xslt>false</xslt>
<pathFromSeed>LL</pathFromSeed>
<md5>WVBM5NDACLWRN4OSXRCQUA5RJA</md5>
</connectorSpecific>
<title>Do I Need Managed Services for My Search and Big Data Applications?</title>
<url>http://www.example.com/big-data-search-managed-services-questions</url>
<UD>http://www.example.com/big-data-search-managed-services-questions</UD>
<size>21467</size>
<displayurl>http://www.example.com/big-data-search-managed-services-questions</displayurl>
<UE>http://www.example.com/big-data-search-managed-services-questions</UE>
<submitTime>2016-07-21T22:55:00+0000</submitTime>
<newContent>Site Map Terms, privacy and cookie</newContent>
<T>Do I Need Managed Services for My Search and Big Data Applications?</T>
<sourceType>heritrix</sourceType><U>http://www.example.com/big-data-search-managed-services-questions</U>
<sourceName>PIB</sourceName>
</_source>
<_id>http://www.example.com/big-data-search-managed-services-questions</_id>
<_score>1</_score>
</hits>
<hits>
</root>
答案 1 :(得分:0)
您可以这样做:
var m_names = new Array("Jan", "Feb", "Mar",
"Apr", "May", "Jun", "Jul", "Aug", "Sep",
"Oct", "Nov", "Dec");
var d = new Date();
var curr_date = d.getDate();
var curr_month = d.getMonth();
var curr_year = d.getFullYear();
var my_date = (curr_date + "-" + m_names[curr_month] + "-" + curr_year);
document.getElementById("DATE_TODAY").value = my_date;
<input type="text" name="DATE_TODAY" id="DATE_TODAY" />
答案 2 :(得分:0)
您的代码段抛出:
未捕获的ReferenceError:未定义makeArray
您可以使用:
{{1}}