如何使用DateBox插件在jQuery Mobile中设置日期框的默认日期? [英] How to set the default date on date box in jQuery mobile with DateBox plugin?

查看:61
本文介绍了如何使用DateBox插件在jQuery Mobile中设置日期框的默认日期?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在jQuery mobile中实现日期框.我正在使用弹出式窗口中的日期框,它正在工作.当用户使用(+)按钮打开弹出屏幕时,我需要在文本字段中设置默认日期(当前日期).

I am implementing the date box in jQuery mobile. I am using the date box in pop up, which is working. I need to set the default date (current date) in the text field when a user opens the pop up screen, using (+) button.

http://jsfiddle.net/ravi1989/uhdYv/

  <div data-role="popup" id="CaseInformationScreen" data-close-btn="none"  data-overlay-theme="a" data-dismissible="false">
                <div data-role="header" data-theme="b" >

                    <a href="#" data-role="button" data-corners="false" id="Cancel">Cancel</a>
                    <h1>Case Information</h1>
                    <a href="#" data-role="button" data-corners="false" id="AddButton">Add</a>
                </div>

                <div data-role="content">
                    <div><img src="img/Documents.png"/></div>
                    <div data-role="fieldcontain">
                        <label for="text-12" style="text-align:top;margin-left: 0px;">Case Name:</label>
                        <input name="text-12" id="text-12" value="" type="text" class="caseName_h" >
                    </div>
                    <div data-role="fieldcontain">
                        <label for="text-12" style="text-align:left;margin-left: 0px;" >Case Date:</label>
                        <!--input name="text-12" id="text-12" value="" type="date" class="caseDate_h"  -->
                           <input name="mydate" id="mydate" type="date" data-role="datebox" data-options='{"mode": "datebox", "useNewStyle":true,"zindex":1200}'/>
                    </div>
                    <div data-role="fieldcontain">
                        <label for="textarea-12">Textarea:</label>
                        <textarea cols="40" rows="8" name="textarea-12" id="text-12" class="caseTextArea_h"></textarea>
                    </div>
                </div>
            </div>

推荐答案

    To set the Text box's value to current date when the popup opens use this code:

    1. Change id of the associated label to myDate:

    <label for="myDate" style="text-align:left;margin-left: 0px;" >Case Date:</label>

    <input name="mydate" id="mydate" type="date" data-role="datebox" data-options='{"mode": "datebox", "useNewStyle":true,"zindex":1200}'/>

    2. JQM code:

    $( "#CaseInformationScreen" ).bind({
       popupafteropen: function(event, ui) { 
                var date = new Date();

                $('#mydate').trigger('datebox', {
                    'method': 'set',
                    'value': date
                }).trigger('datebox', {
                    'method': 'doset'
                });


       }
    });

这篇关于如何使用DateBox插件在jQuery Mobile中设置日期框的默认日期?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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