问题描述
我有一种情况,我必须在MM/DD/YYYY格式的文本框中输入日期,并且还有另一个文本框,其中值应自己填写,并且值必须距输入日期正好一个月,即如果我在第一个文本框中的值是05/07/2012第二个文本框应自动拥有2012年5月8日,并且这应该由javascript完成,以下是我尝试的代码,但第二个文本框的取值与第一个文本框,有人可以帮我解决这个问题,并告诉我代码有什么问题吗
Hi,
I have a scenario where I have to enter a date in a text box in MM/DD/YYYY format and there is another text box where the value should be filled by itself and the value must be exactly one month from the entered date i.e, if my value in the first text box is 05/07/2012 second text box should automatically possess 05/08/2012 and this should be done by javascript, below is the code I tried but the second text box is taking the same value as the first text box, can someone please help me out with this issue and tell me what''s wrong with the code
function populateArchiveDate() {
var frm=document.form1
if (validateDateFormat(frm.story_intro_date) && frm.story_exp_date.disabled == false) {
var post_date = new Date(frm.story_intro_date.value);
alert(post_date.getMonth());
var expiration_date = new Date(post_date.setMonth(post_date.getMonth() + 1));
alert(expiration_date.getMonth());
if (expiration_date.getMonth() == 0)
expiration_date = expiration_date.getMonth() + 1 + "/" + expiration_date.getDate() + "/" + expiration_date.getFullYear();
else
expiration_date = expiration_date.getMonth() + "/" + expiration_date.getDate() + "/" + expiration_date.getFullYear();
frm.story_exp_date.value = expiration_date;
frm.hdn_story_exp_date.value = expiration_date;
在此先感谢
Thanks in advance
推荐答案
<script type="text/javascript">
这篇关于使用javasript在输入的日期中添加一个月的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!