从Grails DatePicker获取日期值 [英] Get Date value from Grails DatePicker

查看:107
本文介绍了从Grails DatePicker获取日期值的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在grails datePicker中获取月,年和日的日期值

How to get date values in month, year and days in grails datePicker

<g:datePicker id="test" name="test" precision="day"></g:datePicker >

我尝试使用 getDate()但我没有任何价值。

I tried using getDate() but I do not get any value.

推荐答案

尝试这种方法,先注册更改处理程序到datePicker标签生成的3个选项中的每一个,然后调用 dateWasChanged 方法和内部,构建您的日期并更新您的 mydate div。

Try this approach, first register change handler to each of the 3 selects generated by the datePicker tag, then call the dateWasChanged method and inside that build your date and update your mydate div.


注意:日期对象月份为0基数(索引),因此您需要从实际选择值中扣除1个单位。 >

Note: On date Object month is 0 base (index) so you need to deduct 1 unit from the actual select value.



    <body>
        <g:datePicker  id="test" name="test" precision="day"></g:datePicker >
        <div id="mydate"></div>

        <script  type="text/javascript" charset="utf-8">
        dateWasChanged()

        $( "#test_day" ).change(function() {
            dateWasChanged();
        });     
        $( "#test_month" ).change(function() {
            dateWasChanged();
        }); 
        $( "#test_year" ).change(function() {
            dateWasChanged();
        }); 

        function dateWasChanged(){
            var year = $( "#test_year" ).val();
            var month = $( "#test_month" ).val()-1;
            var day = $( "#test_day" ).val();
            var date = new Date(year,month,day);
             $("#mydate").text(date.toString())
        }
        </script>
    </body>

这篇关于从Grails DatePicker获取日期值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆