dongyutan1703 2014-08-12 07:26
浏览 59

选择并显示区域jquery日期选择器,但保存在已转换的格里高利日期

I am using an input field element and jquery datepicker in a smarty tpl file like below

MySmarty.tpl:

...        
    <input type="text" id="date_test" />
        <script type="text/javascript">
            {literal}
            $(document).ready(function(){
            $('#date_test').datepicker({dateFormat: 'yy-mm-dd'
        }).datepicker($.datepicker.regional['fa'])
    });
    {/literal}</script>
...

The user select a date from my regional datepicker like 1393-05-21 and save it to the database.

I need to save converted gregorian date 2014-08-12 to the database.

in this case: select and show regional date is correct but save is incorrect.

So i changed the code like below:

    <input type="text" id="date_test" />
    <script type="text/javascript">
        {literal}
        $(document).ready(function(){
        $('#date_test').datepicker({dateFormat: 'yy-mm-dd',
        onSelect: function(dateStr, inst) {
        var date = new gregorian_date(inst.selectedYear, inst.selectedMonth, inst.selectedDay);
        $(this).val(date.getFullYear() + '-' + (date.getMonth()+1) + '-' + date.getDate());
        } 
    }).datepicker($.datepicker.regional['fa'])
});
{/literal}</script>

The problem is: it shows gregorian date value in the box field. It should be like this:

Real value:2014-08-12 show value:1393-05-21

in this case: select regional date and save is correct,but show is incorrect.

Comment: gregorian_date is a custom function

  • 写回答

1条回答 默认 最新

  • duanqun9740 2014-08-13 01:52
    关注

    Datepicker provides a method to set the date value. Try that:

    $('#date-test').datepicker({
        dateFormat: 'yy-mm-dd',
        onSelect: function(value, dp) {
            var gregDate = gregorian_date(dp.selectedYear, dp.selectedMonth, dp.selectedDay);
            $('#date-test').datepicker('setDate', gregDate);
        }
    });
    

    Here's a fiddle to demonstrate:

    http://jsfiddle.net/klenwell/jqadkmud/3/

    Take note: after updating the value, changing the date value for the user quickly gets confusing. It may make more sense to list the Gregorian date in another field.

    For example:

    http://jsfiddle.net/klenwell/jqadkmud/4/

    评论

报告相同问题?

悬赏问题

  • ¥15 redis-full-check比较 两个集群的数据出错
  • ¥15 Matlab编程问题
  • ¥15 训练的多模态特征融合模型准确度很低怎么办
  • ¥15 kylin启动报错log4j类冲突
  • ¥15 超声波模块测距控制点灯,灯的闪烁很不稳定,经过调试发现测的距离偏大
  • ¥15 import arcpy出现importing _arcgisscripting 找不到相关程序
  • ¥15 onvif+openssl,vs2022编译openssl64
  • ¥15 iOS 自定义输入法-第三方输入法
  • ¥15 很想要一个很好的答案或提示
  • ¥15 扫描项目中发现AndroidOS.Agent、Android/SmsThief.LI!tr