Bootstrap datepicker not woking in modal

梦想与她 提交于 2019-12-11 07:22:43

问题


When I use a datepicker inside a modal the datepicker is not working.

I use the event show.bs.modal to modify some content of the modal on show:

$(function(){
    $('#statusModal').on('show.bs.modal', function (event) {
        var button = $(event.relatedTarget);
        var title = button.data('title');
        var input_date = button.data('date');
        var modal = $(this);

        modal.find('.modal-title').text('Clicked: ' + title);
        modal.find('.modal-body #inputDate').val(input_date);

        $('#inputDate').datepicker();

    }).on('hidden.bs.modal', function (event) {
        $('#inputDate').datepicker('remove');
    });

    $('#inputDate2').datepicker();

})

But this event gets fired again when the datepicker opens. Because of this, it delets the value of the date input. And selecting a date does also not work.

Here a jsfiddle that demonstrates the problem: http://jsfiddle.net/f9de9z8x/26/

Any idea what's wrong?


回答1:


Try using the shown event instead of the show event.

$('#statusModal').on('shown.bs.modal', function (event) {

http://jsfiddle.net/kp0q9s9L/




回答2:


Try this,

$("input.date-picker").click(function(){

$("#ui-datepicker-div").css("z-index",5000);    

});



来源:https://stackoverflow.com/questions/28721516/bootstrap-datepicker-not-woking-in-modal

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