且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

带有eonasdan DatePicker的DataTables不起作用

更新时间:2023-08-22 22:33:04

您正在动态添加重复的ID,代码在页面加载时运行时不会接收它们!



仍然从Github添加脚本,这是令人皱眉的!我已经替换了来自 cdnjs 的引用。 PLease参考有关直接从Github链接文件的信息。



此更新的 JSFiddle 的作品将为您提供工作基础从



基本上我已经在表中添加了一个回调,这意味着你动态添加的 datetimepicker 将会被正确初始化(第65行)。 这是一个有趣的概念, b

 
fnDrawCallback:function(){
$(。date)。datetimepicker();
}


I have trouble with eonasdan DatePicker, i don't understand what i messed up... I think I have verified to have all the necessary resources but when i click in calendar icon nothing happens :\

Live code : live example


I have followed the installation instructions and manual and demos.

Quoting:

Minimal Requirements
jQuery
Moment.js
Bootstrap.js (transition and collapse are required if you're not using the full Bootstrap)
Bootstrap Datepicker script
Bootstrap CSS
Bootstrap Datepicker CSS
Locales: Moment's locale files are here

Scripts needed:

<script type="text/javascript" src="/path/to/jquery.js"></script>  
<script type="text/javascript" src="/path/to/moment.js"></script>  
<script type="text/javascript" src="/path/to/bootstrap/js/transition.js"></script>  
<script type="text/javascript" src="/path/to/bootstrap/js/collapse.js"></script>  
<script type="text/javascript" src="/path/to/bootstrap/dist/bootstrap.min.js"></script>  
<script type="text/javascript" src="/path/to/bootstrap-datetimepicker.min.js"></script>  

CSS styles

<link rel="stylesheet" href="/path/to/bootstrap-datetimepicker/build/css/bootstrap-datetimepicker.min.css" />  

You were dynamically adding IDs which were duplicated, your checking code wouldn't pick them up as it ran when the page loaded only! See more about this later.

You were still adding script from Github, which is frowned upon! I've replaced the references from ones from cdnjs. PLease refer to this about linking files directly from Github.

This updated JSFiddle works and will give you a basis to work from.

Basically I've added a callback to the table which will mean that your dynamically added datetimepickers will be initialised correctly (line 65). You're not able to interact with something unless it's within the DOM. This is an interesting concept to get your head around but well worth bearing in mind!

,
"fnDrawCallback": function() {
    $(".date").datetimepicker();
}