Does not work datepicker (Bootstrap)?

半世苍凉 提交于 2019-12-12 04:49:17

问题


To be displayed in the input - calendar (datepicker (Bootstrap)). The problem is that in the former case, it appears:

<input type="text" class="datepicker_goal" data-provide="datepicker" value="Period">

$('.modal-body input[data-provide="datepicker"]').datepicker();

But I have a modal window is created when you activate another form tag and added:

<input type="text" class="datepicker_goal_modal" data-provide="datepicker_modal" value="Period">

$('.modal-body input[data-provide="datepicker_modal"]').datepicker();

But in the second embodiment, datepicker is not activated and the calendar is not visible. And even conflicting something closes the modal window. Tell me what I did wrong and how to fix it? How to display the calendar in all fields modal form?


回答1:


Here is the working Jsfiddle for reference. It has modal popup and datepicker attached to input field.

$('input[data-provide="datepicker"]').datepicker();    

// Append New Input field
$("div.modal-body").append(" <input type=\"text\" class=\"datepicker_goal_modal\" data-provide=\"datepicker_modal\" placeholder=\"Period\">")

// After appending, call datepicker on input field.
$('.modal-body input[data-provide="datepicker_modal"]').datepicker();



回答2:


$('body').on('focus', '.datepicker_goal_modal', function(){
    $(this).datepicker();
});​

This should work. The reason it would not appear before is because you are dynamically creating the modal, and the element selector function only works on elements that existed when the page first loaded.



来源:https://stackoverflow.com/questions/27336071/does-not-work-datepicker-bootstrap

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