简体   繁体   English

jQuery-ui小部件已呈现

[英]jQuery-ui widget is rendered

How to check if a jQuery-ui widget is rendered or not (version 1.11.2)? 如何检查是否渲染了jQuery-ui小部件(1.11.2版)? To avoid Uncaught Error: cannot call methods on xxxx prior to initialization; attempted to call method 'xxxx' 为了避免Uncaught Error: cannot call methods on xxxx prior to initialization; attempted to call method 'xxxx' Uncaught Error: cannot call methods on xxxx prior to initialization; attempted to call method 'xxxx' errors. Uncaught Error: cannot call methods on xxxx prior to initialization; attempted to call method 'xxxx'错误。

One way is to use the data api like 一种方法是像这样使用数据API

If your widget name is datepicker and the element id is date then 如果您的小部件名称是datepicker,而元素ID是date

if($('#date').data('datepicker')){
    //call method since it is initialized
}

Demo: Fiddle 演示: 小提琴


The same can be done via the :data() selector 可以通过:data()选择器完成相同的操作

if ($('#date').is(':data(datepicker)')) {
    //call method since it is initialized
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM