0

我需要在 ajax 加载的 div 中的输入上加载数据时间选择器 .appendDtpicker()。

这是我试图实现的 js 代码:

$(document).on('click', "#start_date_q", function(){
        $("#start_date_q").appendDtpicker({"dateFormat": "YYYY-MM-DD h:m","minuteInterval": 15,"closeOnSelected": true,"calendarMouseScroll": false}); 
        });

这是我之前从 ajax 调用中得到的 html:

<div id="ajax results"><input type="text" id="start_date_q" name="start_date_q" value="'></div>

我在控制台中收到此错误:

Uncaught TypeError: Object [object Object] has no method 'appendDtpicker' 

我也试过这个JS代码:

function select_date(type){

        $("#"+type).appendDtpicker({"dateFormat": "YYYY-MM-DD h:m","minuteInterval": 15,"closeOnSelected": true,"calendarMouseScroll": false}); 


     }

和html:

<div id="ajax results"><input type="text" id="start_date_q" name="start_date_q" value="" onclick="select_date('start_date_q')"></div>

显示相同的错误。

当我在另一个输入(未加载 ajax)上实现相同的 JS 时,它确实显示了日期时间选择器。

我用过这个 JS 插件:https ://github.com/mugifly/jquery-simple-datetimepicker 请任何人帮助我!

4

2 回答 2

0

尝试这个:

$(document).on('click', "#start_date_q", 
    function(){ 
        alert('ok'); 
        $.getScript("js/jquery.simple-dtpicker.js", function() { 
            alert('ok1');
            setTimeout( function() { 
                $("#start_date_q").appendDtpicker(
                    {"dateFormat": "YYYY-MM-DD h:m",
                    "minuteInterval": 15,
                    "closeOnSelected": true,
                    "calendarMouseScroll": false
                }); 
            }, 100);
        });
});
于 2013-09-19T10:44:29.003 回答
0

首先确保您的脚本正在加载。使用 chrome 或 ie 开发者工具来检查。还要确保在 jquery 引用之后从您的页面引用https://github.com/mugifly/jquery-simple-datetimepicker插件。

<script src="pathtojquery"></script>
<script src="pathtoplugin"></script>
于 2013-09-19T09:33:23.407 回答