jQuery Mobile 日期选择器配置

发布于 2024-11-06 17:04:38 字数 2785 浏览 1 评论 0原文

我正在开发 Web 应用程序的移动版本,但在 jQ mobile 中配置日期选择器时遇到一些问题。我知道这是一个实验性功能(我想它可能有点问题?),但我认为配置它应该不是问题。

但是,我似乎无法让它发挥作用。我查看了 jQ UI 文档,为我的日期选择器提供了以下配置:

    $(document).ready(function(){
         $("#mo_date").datepicker({ 
                                    showAnim: 'fadeIn', 
                                    dateFormat: 'dd-mm-yy',
                                    dayNamesShort: ['Zon', 'Maa', 'Din', 'Woe', 'Don', 'Vrij', 'Zat'],
                                    dayNamesMin:  ['Zon', 'Maa', 'Din', 'Woe', 'Don', 'Vrij', 'Zat'],
                                    dayNames: ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'],
                                    monthNames: ['Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'],
                                    monthNamesShort: ['Jan','Feb','Maa','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'],
                                    minDate: 0,
                                    // altField outputs date in mySQL date format yy-m-d. datum hieruit halen, ipv .datepicker('getDate');
                                //  altField: '.output_date',
                                //  altFormat: 'yy-m-d'
                                });
    });

我的 HTML 如下:

<form action="mobile/go" method="post"> 
        <div data-role="fieldcontain">
            <label for="mo_event_type" class="select">Kies type taak</label>
            <select name="mo_event_type" id="mo_event_type" data-native-menu="false">
                <option data-placeholder="true">Taaktype</option>
                <option value="huiswerk">Huiswerk</option>
                <option value="deadline">Deadline</option>
                <option value="vrijetijd">Vrije tijd</option>
            </select>
        </div>
        <div data-role="fieldcontain">
            <label for="mo_title">Titel</label>
            <input type="text" name="mo_title" value="" id="mo_title" data-theme="b"/>
        </div>
        <div data-role="fieldcontain">
            <label for="mo_descr">Beschrijving</label>
            <textarea cols="20" rows="8" name="mo_descr" id="mo_descr" data-theme="b"></textarea>
        </div>
        <div date-role="fieldcontain">
            <label for="mo_date">Datum</label>
            <input type="date" name="mo_date" id="mo_date" value="" />
        </div>
    </form>

我是否在这里遗漏了一些重要的内容,或者我只是做错了?一些见解将不胜感激。我知道配置很好,因为我在非移动应用程序中使用了相同的配置。只是无法让它与移动设备一起使用:(

非常感谢。

I'm working on a mobile version of my web application, but I have some trouble with configuring a datepicker in jQ mobile. I know it's an experimental feature (I suppose it might be a bit buggy?), but I figured configuring it shouldn't really be a problem.

However, I can't seem to get it working. I looked at the jQ UI documentation to come up with the following configuration for my datepicker:

    $(document).ready(function(){
         $("#mo_date").datepicker({ 
                                    showAnim: 'fadeIn', 
                                    dateFormat: 'dd-mm-yy',
                                    dayNamesShort: ['Zon', 'Maa', 'Din', 'Woe', 'Don', 'Vrij', 'Zat'],
                                    dayNamesMin:  ['Zon', 'Maa', 'Din', 'Woe', 'Don', 'Vrij', 'Zat'],
                                    dayNames: ['Zondag', 'Maandag', 'Dinsdag', 'Woensdag', 'Donderdag', 'Vrijdag', 'Zaterdag'],
                                    monthNames: ['Januari','Februari','Maart','April','Mei','Juni','Juli','Augustus','September','Oktober','November','December'],
                                    monthNamesShort: ['Jan','Feb','Maa','Apr','Mei','Jun','Jul','Aug','Sep','Okt','Nov','Dec'],
                                    minDate: 0,
                                    // altField outputs date in mySQL date format yy-m-d. datum hieruit halen, ipv .datepicker('getDate');
                                //  altField: '.output_date',
                                //  altFormat: 'yy-m-d'
                                });
    });

My HTML is as follows:

<form action="mobile/go" method="post"> 
        <div data-role="fieldcontain">
            <label for="mo_event_type" class="select">Kies type taak</label>
            <select name="mo_event_type" id="mo_event_type" data-native-menu="false">
                <option data-placeholder="true">Taaktype</option>
                <option value="huiswerk">Huiswerk</option>
                <option value="deadline">Deadline</option>
                <option value="vrijetijd">Vrije tijd</option>
            </select>
        </div>
        <div data-role="fieldcontain">
            <label for="mo_title">Titel</label>
            <input type="text" name="mo_title" value="" id="mo_title" data-theme="b"/>
        </div>
        <div data-role="fieldcontain">
            <label for="mo_descr">Beschrijving</label>
            <textarea cols="20" rows="8" name="mo_descr" id="mo_descr" data-theme="b"></textarea>
        </div>
        <div date-role="fieldcontain">
            <label for="mo_date">Datum</label>
            <input type="date" name="mo_date" id="mo_date" value="" />
        </div>
    </form>

Am I missing something crucial here or am I just doing it plain wrong? Some insight would be appreciated. I know the configuration is fine since I'm using the same for my non-mobile application. Just can't get it to work with the mobile one :(

Thanks a lot.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雨巷深深 2024-11-13 17:04:38

首先,我更喜欢 DateBox 插件: http://dev.jtsage.com/jQM-DateBox /

在实验 DP 的文档中:http://jquerymobile.com/demos/1.0a4.1/experiments/ui-datepicker/

<script>
  //reset type=date inputs to text
  $( document ).bind( "mobileinit", function(){
    $.mobile.page.prototype.options.degradeInputs.date = true;
  });   
</script>

请务必将此事件绑定放在在 jQuery 之后、jQuery Mobile 之前加载的脚本中。检查此页面的源代码以获取示例。

我还注意到,许多人无法获得与 DP 一起使用的附加选项,

我为 DateBox:

<input type="date" 
       name="mo_date" 
       id="mo_date" value="" 
       data-options='{
           "dateFormat": "DD-MM-YYYY", 
           "noButtonFocusMode": "true", 
           "headerFormat": "DD-MM-YYYY", 
           "daysOfWeekShort" : [
                                   "Zon", 
                                   "Maa", 
                                   "Din", 
                                   "Woe", 
                                   "Don", 
                                   "Vrij", 
                                   "Zat"
                               ], 
           "mode": "calbox", 
           "minYear" : "0", 
           "monthsOfYear" : [
                                "Januari",
                                "Februari",
                                "Maart",
                                "April",
                                "Mei",
                                "Juni",
                                "Juli",
                                "Augustus",
                                "September",
                                "Oktober",
                                "November",
                                "December"
                            ] 
       }'  
       data-role="datebox" />

单行版本提供了这个:

<input type="date" name="mo_date" id="mo_date" value="" data-options='{"dateFormat": "DD-MM-YYYY", "noButtonFocusMode": "true", "headerFormat": "DD-MM-YYYY", "daysOfWeekShort" : ["Zon", "Maa", "Din", "Woe", "Don", "Vrij", "Zat"], "mode": "calbox", "minYear" : "0", "monthsOfYear" : ["Januari","Februari","Maart","April","Mei","Juni","Juli","Augustus","September","Oktober","November","December"] }'  data-role="datebox" />

First I like the DateBox plugin a little better IMO: http://dev.jtsage.com/jQM-DateBox/

In the Documentation for the Experimental DP: http://jquerymobile.com/demos/1.0a4.1/experiments/ui-datepicker/

<script>
  //reset type=date inputs to text
  $( document ).bind( "mobileinit", function(){
    $.mobile.page.prototype.options.degradeInputs.date = true;
  });   
</script>

Be sure to place this event binding in a script that loads after jQuery, but before jQuery Mobile. Check this page's source for an example.

I have also noticed that many can not get additional options to work with the DP

I had this for the DateBox:

<input type="date" 
       name="mo_date" 
       id="mo_date" value="" 
       data-options='{
           "dateFormat": "DD-MM-YYYY", 
           "noButtonFocusMode": "true", 
           "headerFormat": "DD-MM-YYYY", 
           "daysOfWeekShort" : [
                                   "Zon", 
                                   "Maa", 
                                   "Din", 
                                   "Woe", 
                                   "Don", 
                                   "Vrij", 
                                   "Zat"
                               ], 
           "mode": "calbox", 
           "minYear" : "0", 
           "monthsOfYear" : [
                                "Januari",
                                "Februari",
                                "Maart",
                                "April",
                                "Mei",
                                "Juni",
                                "Juli",
                                "Augustus",
                                "September",
                                "Oktober",
                                "November",
                                "December"
                            ] 
       }'  
       data-role="datebox" />

single line version:

<input type="date" name="mo_date" id="mo_date" value="" data-options='{"dateFormat": "DD-MM-YYYY", "noButtonFocusMode": "true", "headerFormat": "DD-MM-YYYY", "daysOfWeekShort" : ["Zon", "Maa", "Din", "Woe", "Don", "Vrij", "Zat"], "mode": "calbox", "minYear" : "0", "monthsOfYear" : ["Januari","Februari","Maart","April","Mei","Juni","Juli","Augustus","September","Oktober","November","December"] }'  data-role="datebox" />
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文