2012-04-09 73 views
2

在我的網站,我有兩個日期輸入,jQuery UI的日期選擇器格式不改變

<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'); 
    }); 

但當我選擇日期,它仍會返回2012年4月4日格式的日期而不是yy-mm-dd。

我應該如何解決這個問題?

感謝

回答

0

大聲笑,又來了。首先:

  • altFormatThe 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

  • DATEFORMATThe format for parsed and displayed dates. This attribute is one of the regionalisation attributes. For a full list of the possible formats see theformatDatefunction.

見工作jsFiddle Here

你MIG ht也想看到我給出的答案few minutes ago here, with more fiddles