Multiple Calendars Displayed or Value Selected not displaying correctly

£可爱£侵袭症+ 提交于 2019-12-31 04:06:07

问题


Ok I'm using the jQuery Mobile Framework and adding the Experimental Date Picker but I encounter two results. Following the instructions on the page, this is what I have so far.

Code Efforts #1:

$(document).ready(function() {        
    $('.hasDatepicker').hide();

    $('#date-of-birth').each(function() {     
        $(this).focus(function() {
            $(this).next().show('fast');
        });

        $(this).blur(function() {               
           $(this).next().hide('fast');
        });
    });
});

Now this shows the one calendar (as I would like) but on date selection the date stays the same (it's todays date) and not the date selected.

Code Efforts #2:

$(function() {
    $('.hasDatepicker').hide();

    $('#date-of-birth').focus(function() {
        $('.hasDatepicker').show('fast');
    });

    $('#date-of-birth').blur(function() {
        $('.hasDatepicker').hide('fast');
    });
});

Now this show multiple calendars (5 to be exact) stacked on top of one another and also if I select the date it works as expected. But I only want one calendar to display.

I would like to combine the two code efforts to get the desired results but nothing really seems to be working.

Here is the HTML

<div data-role="fieldcontain">
    <label for="date-of-birth">Date of Birth</label>
    <input type="date" name="date-of-birth" id="date-of-birth" />                
</div>

The type="date" is how you call the date picker

Any tips?

Other Stack Links that might shed some light

  • Link 1
  • Link 2

UPDATE:

Well this might be the issue but still haven't found a solution.

I using the Multi-page layout option for jQueryMobile, For each page it creates an additional date-picker but it displays them stack on each other and the functionality doesn't work correctly


回答1:


I got it working. I asked this question: jQuery Mobile -> Override jQuery UI Datepicker -> Layout broken

It is experimental, but it works. You should not use this

$('.hasDatepicker').show('fast');

You should add for each datepicker on one site a unique id and then write:

$('#uniqueId').show('fast');

I add the IDs inside of the JavaScript file of the datepicker.



来源:https://stackoverflow.com/questions/5005565/multiple-calendars-displayed-or-value-selected-not-displaying-correctly

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!