jquery ui datepicker格式不会改变

时间:2012-04-09 20:07:17

标签: jquery-ui datepicker

在我的网站上,我有两个日期输入,

 <label>From : </label><input class="datepicker" id="from" name="from" value="<?php echo $from;?>" size=11 type="text">
 <label>To : </label><input class="datepicker" id="to" name="to" value="<?php echo $to ;?>" size=11 type="text">

在javascript部分,我有以下代码

$(function() {
  $( ".datepicker" ).datepicker({ altFormat: 'yy-mm-dd' });
  //getter
  var altFormat = $( ".datepicker" ).datepicker( "option", "altFormat" );
  //setter
  $( ".datepicker" ).datepicker( "option", "altFormat", 'yy-mm-dd' );
  });

但是当我选择日期时,它仍然会返回04/04/2012格式的日期,而不是yy-mm-dd。

我该如何解决这个问题?

由于

1 个答案:

答案 0 :(得分:0)

大声笑,我们再来一次。首先:

  • altFormat The dateFormat to be used for the altField option. This allows one date format to be shown to the user for selection purposes, while a different format is actually sent behind the scenes. For a full list of the possible formats see the formatDate function

  • dateFormat The format for parsed and displayed dates. This attribute is one of the regionalisation attributes. For a full list of the possible formats see the formatDate function.

请参阅工作jsFiddle Here

您可能还希望看到我给出few minutes ago here, with more fiddles的答案。