0

遗漏的类型错误的财产“的getTime”:无法读取的不确定
财产“的getTime”你可以找到错误日志here引导datetimepicker-遗漏的类型错误:无法读取未定义

$('.modal-body').on("focus","#date",function() { 
    var date = $('#date').val(); 
    $('#date').datetimepicker({ 
     defaultDate: date, 
     language: 'zh-CN', 
     pickDate: true, 
     pickTime: true, 
     autoclose: true, 
     format: 'yyyy-mm-dd', 
     todayBtn: true, 
     minView: 2, 
     startView: 3, 
     pickerPosition: "bottom-left" 
    }); 
); 

插入弹出窗口

$('#edit').click(function(){ 
    $.ajax({ 
     url: "{:U('SystemSettingMgt/settingConf')}", 
     type: 'post', 
     data: { 
      'id' : $(this).siblings('input').val(), 
      'is_active' : 1, 
     }, 
     success:function(json){ 
      $('.modal-body').children().empty(); 
      var str = ''; 
      switch(json.datatype){ 
       // yes/false 
       case "1": 
        str += '<label>select setting</label>'; 
        str += '<input type="hidden" id="id" value="'+json.id+'">'; 
        str += '<input type="hidden" id="datatype" value="'+json.datatype+'">'; 
        str += '<select name="value" id="value" class="form-control">'; 
        if (json.value == 1) { 
         str += '<option value="1" selected>yes</option>'; 
         str += '<option value="0"false</option>'; 
        }else if(json.value == 0){ 
         str += '<option value="1">yes</option>'; 
         str += '<option value="0" selected>false</option>'; 
        } 
        str += '</select>'; 
        $('.modal-body').children().append(str); 
        break; 

       // enter string 
       case "2": 
        str += '<label>enter setting</label>'; 
        str += '<input type="hidden" id="id" value="'+json.id+'">'; 
        str += '<input type="hidden" id="datatype" value="'+json.datatype+'">'; 
        str += '<input name="value" id="value" class="form-control" value="'+json.value+'">'; 
        $('.modal-body').children().append(str); 
        break; 

       // enter num 
       case "3": 
        str += '<label>select setting</label>'; 
        str += '<input type="hidden" id="id" value="'+json.id+'">'; 
        str += '<input type="hidden" id="datatype" value="'+json.datatype+'">'; 
        str += '<input type="text" id="value" value="'+json.value+'" name="value" class="form-control" placeholder="设定值" onkeyup="if(! /^\d+$/.test(this.value)){this.placeholder='+'只能整数'+';this.value='+';}">'; 
        $('.modal-body').children().append(str); 
        break; 

       // select date 
       case "4": 
        str += '<label>select setting</label>'; 
        str += '<input type="hidden" id="id" value="'+json.id+'">'; 
        str += '<input type="hidden" id="datatype" value="'+json.datatype+'">'; 
        str += '<input type="text" id="date" name="value" class="form-control date" placeholder="select date" value="'+json.value+'">'; 
        $('.modal-body').children().append(str); 
        break; 

       // date 
       case "5": 
        str += '<label>change setting</label>'; 
        str += '<input type="hidden" id="id" value="'+json.id+'">'; 
        str += '<input type="hidden" id="datatype" value="'+json.datatype+'">'; 
        str += '<input type="text" data-date-format="hh:ii" id="time" name="value" class="form-control date" placeholder="select time" value="'+json.value+'">'; 
        $('.modal-body').children().append(str); 
        break; 

       // select 
       case "6": 
        str += '<label>change setting</label>'; 
        str += '<input type="hidden" id="id" value="'+json.id+'">'; 
        str += '<input type="hidden" id="datatype" value="'+json.datatype+'">'; 
        str += '<select name="datasource" id="value" class="form-control">'; 
        for(i = 0; i < json.datasource.length; i++){ 
         str += '<option value="'+i+'">'+json.datasource[i]+'</option>'; 
        } 
        str += '</select>'; 
        $('.modal-body').children().append(str); 
        break; 
       } 
     } 
    }); 
    $('#editSetting').modal('show'); 
}); 

我想时间格式的问题,而是通过jQuery的值会在错误发生后发出。

+0

请分享您的代码小提琴 – Aslam

回答

0

Uncaught TypeError: Cannot read property "getTime" of undefined

当你没有包含jQuery UI插件时抛出此错误。
除了jQuery插件之外,请确保将其包含在项目中的任何其他脚本之前。

+0

但在其他页面上,同样的代码就可以了。我猜这是jQuery冲突,但也被拒绝 –

+2

尽管在其他页面中可以使用相同的代码,但对于此页面,jQuery调用jQuery库的层次结构可能会有所不同。因此,由于jQuery库导入的顺序,可能相同的代码在此页面中失败。 – Lahiru

+0

我发现问题了,是问题的时间格式,用json.value加去,但会给出,我现在需要解决时间格式问题 –

1

在自举-datetimepicker.js是:

getDate: function() { 
     var d = this.getUTCDate(); 
     if (d === null) { 
     return null; 
     } 
     return new Date(d.getTime() + (d.getTimezoneOffset() * 60000)); 
    }, 

但是当设置例如输入的值:12:15然后d是未定义的。你可以在你的代码重写GETUTCDATE功能或改变,如果到:

d === null || typeof d ==='undefined' 
相关问题