4

我一直坚持这个问题。日期选择器在静态内容上运行良好。

但是通过 Ajax 加载内容时失败。

我努力了 :-

jQuery.noConflict();
jQuery(function($) {
    $(document).ready(function(){
        $( ".datepickerRange" ).datepicker({
            dateFormat: 'dd-mm-yy',
            prevText:'',
            nextText:'',
            minDate: 0,
            maxDate: "+1M",
            showOn: "button",
            buttonImage: divadatepicker.image_url+"/calendar.jpeg",
            buttonImageOnly: true
        });
        $( ".datepicker" ).datepicker({
            dateFormat: 'dd-mm-yy',
            prevText:'',
            nextText:'',
            showOn: "button",
            buttonImage: divadatepicker.image_url+"/calendar.jpeg",
            buttonImageOnly: true,
            changeMonth: true,
            changeYear: true,
            yearRange: "1960:2015"
        });

            });

$(document).live(function(){
        $( ".datepickerRange" ).datepicker({
            dateFormat: 'dd-mm-yy',
            prevText:'',
            nextText:'',
            minDate: 0,
            maxDate: "+1M",
            showOn: "button",
            buttonImage: divadatepicker.image_url+"/calendar.jpeg",
            buttonImageOnly: true
        });
        $( ".datepicker" ).datepicker({
            dateFormat: 'dd-mm-yy',
            prevText:'',
            nextText:'',
            showOn: "button",
            buttonImage: divadatepicker.image_url+"/calendar.jpeg",
            buttonImageOnly: true,
            changeMonth: true,
            changeYear: true,
            yearRange: "1960:2015"
        });

            });

});

通过 ajax 加载内容后,它没有显示均匀的日历小图像。

4

2 回答 2

11

在您的 ajax调用中调用.datepicker您的success回调函数,而不是使用.live已弃用的 using 。例子:

function initdatepicker(){
    $( ".datepickerRange" ).datepicker({
        dateFormat: 'dd-mm-yy',
        prevText:'',
        nextText:'',
        minDate: 0,
        maxDate: "+1M",
        showOn: "button",
        buttonImage: divadatepicker.image_url+"/calendar.jpeg",
        buttonImageOnly: true
    });
    $( ".datepicker" ).datepicker({
        dateFormat: 'dd-mm-yy',
        prevText:'',
        nextText:'',
        showOn: "button",
        buttonImage: divadatepicker.image_url+"/calendar.jpeg",
        buttonImageOnly: true,
        changeMonth: true,
        changeYear: true,
        yearRange: "1960:2015"
    });
}
$(document).ready(function(){
    initdatepicker();
});

并将其添加到您的$.ajax success

initdatepicker();
于 2013-05-27T12:09:09.020 回答
-1

用这个

<script type="text/javascript">
    $(function(){
        $('input.calendarSelectDate').live('click', function() {
           $(this).datepicker({showOn:'focus'}).focus();
        });
     });
</script>
于 2013-06-05T14:00:34.200 回答