标签: javascript jquery jquery-ui
如何检查是否呈现了jQuery-ui小部件(版本1.11.2)?为了避免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'
答案 0 :(得分:1)
一种方法是使用数据api,如
如果您的窗口小部件名称是datepicker,而元素ID是date则
date
if($('#date').data('datepicker')){ //call method since it is initialized }
演示:Fiddle
可以通过:data()选择器
if ($('#date').is(':data(datepicker)')) { //call method since it is initialized }