今天在项目里用到一个jQuery的时间插件,一开始自己写的测试demo完全么的问题

但当我把它放到项目里时问题来了,报了一个错:Cannot read property 'top' of undefined

html代码是这样的:↓

<div class="inputLine" >
<input type="text" id="portInDate" placeholder="Expected Port-in Date" value="">
<i class="date"></i>
</div>

点到时间库里看了一下

大概意思就是jquery获取到该元素的offset()里没有top这个属性,也就是获取不到该元素距离文档顶部的距离

这是为什么呢?

input外层div的position属性是relative

div中position:relative与position:absolute的区别

position:absolute是通过left和top定位的,而position:relative是通过margin-left等定位的,所以子元素获取不到top属性。

然后我把代码改了一下↓把id放在了div上

<div class="inputLine" id="portInDate">
<input type="text" placeholder="Expected Port-in Date" value="">
<i class="date"></i>
</div>

然后运行

good

jquery.datetimepicker中报错Cannot read property 'top' of undefined的更多相关文章

  1. 小程序 for循环 报错 Cannot read property 'total' of undefined

    for循环一直报错  Cannot read property 'total' of undefined,但total在起初是有定义的,后来找到了问题,是i<=的问题,改为<不报错了. i ...

  2. datatables 多一列报错Cannot read property 'sWidth' of undefined(…)/少一列报错Cannot read property 'style' of undefined(…)

    datatables 多一列报错Cannot read property 'sWidth' of undefined(…)/少一列报错Cannot read property 'style' of u ...

  3. vue.config.js报错cannot set property "preserveWhitespace" of undefined

    vue.config.js报错cannot set property "preserveWhitespace" of undefined 最近在项目中配置webpack,由于vue ...

  4. [Element-UI] 使用Element-UI的DateTimePicker组件报错:Cannot read property 'getHours' of undefined

    使用Element-UI组件的DateTimePicker,如下: <template> <div class="block"> <span clas ...

  5. echarts报错Cannot read property 'features' of undefined

    引入地图的时候 echarts2报错: Uncaught Error: [MODULE_MISS]"echarts/src/util/mapData/params" is not ...

  6. UEditor使用报错Cannot set property 'innerHTML' of undefined

    仿用UEditor的setContent的时候报错,报错代码如下Uncaught TypeError: Cannot set property ‘innerHTML’ of undefined.调试u ...

  7. Vue tools开发工具报错Cannot read property '__VUE_DEVTOOLS_UID__' of undefined

    使用 vue tools 开发工具,不显示调试面板中的组件,点击控制台报错: Cannot read property 'VUE_DEVTOOLS_UID' of undefined 在 main.j ...

  8. 使用vue-preview报错Cannot read property 'open' of undefined

    最近在做一个vue项目中时,需要使用vue-preview插件制作缩略图,首先在终端使用npm i vue-preview -S指令安装了vue-preview插件,然后在main.js中,导入并引用 ...

  9. Chrome下使用百度地图报错Cannot read property 'minZoom' of undefined

    问题:工作中在Google chome下面的js console里面测试百度地图API var map = new BMap.Map("container"); map.cente ...

随机推荐

  1. CSAPP

    陆陆续续花了2个月的时间终于把这个久负盛名的CSAPP看完了,不愧为一本名副其实的经典书籍.有种相见恨晚的感觉,以至于从不会写书评的我也情不自禁的想说点什么.  这本书的书名叫"Comput ...

  2. 简明 homebrew

    介绍 包管理工具几乎已经成为现代操作系统或者开发平台不可或缺的工具软件,无论做开发,或是管理服务器,都免不了用到一些第三方依赖包.包管理工具的基本功能就是提供一个集中的平台,可以在这里找到大部分流行的 ...

  3. 51nod 1133 不重叠的线段 (贪心,序列上的区间问题)

    题意: 最多能选几条不重叠的线段 思路: 按R从小到大排序,维护一个最大的右端点 右端点最小的那个线段是必选的,可以贪心地证明 代码: #include<iostream> #includ ...

  4. Go语言实现:【剑指offer】链表中倒数第k个结点

    该题目来源于牛客网<剑指offer>专题. 输入一个链表,输出该链表中倒数第k个结点. Go语言实现: type ListNode struct { Val int Next *ListN ...

  5. linux下使用gdb对php源码调试

    title: linux下使用gdb对php源码调试 date: 2018-02-11 17:59:08 tags: --- linux下使用gdb进行php调试 调试了一些php的漏洞,记录一下大概 ...

  6. Liunx 上安装java

    linux系统的基本指令 http://www.cnblogs.com/sxdcgaq8080/p/7470796.html ===================================== ...

  7. kubernetes集合

    kubernetes集合 kubernetes(1):kubernetes简介和组件 kubernetes(2):yum安装kubernetes kubernetes(3):kubeadm安装k8s1 ...

  8. hexo博客

    安装软件 node.js(建议稳定版本,本人安装v8.11.3) npm install -g hexo-cli hexo init myBlog //初始化,在myBlog的文件夹下建立网站 hex ...

  9. Linux内存管理解析(三) : 内核对内核空间的内存管理

    内核采用 struct page 来表示一个物理页,在其中记载了诸多物理页的属性,比如 物理页被几个线程使用(如若没有则表示该页可以释放),页对应的虚拟地址. 首先需要知道的是,分配物理页可以分为两个 ...

  10. C# 四则运算及省市选择及日月选择

    using System; using System.Collections.Generic; using System.ComponentModel; using System.Data; usin ...