2016年10月23日 星期日

解決:jquery ui: cannot call methods on dialog prior to initialization; attempted to call method 'isOpen'

錯誤使用jquery ui的isoOpen function


要確認jquery的dialog是否為開啟,設定以下jquery dialog

<script>
 $( function() {
    $( "#dialog-confirm" ).dialog({
      resizable: false,
      height: "auto",
      width: 400,
      modal: true,
 autoOpen: true,
      buttons: [{
      text: "Ok",
      click: function() {
        $( this ).dialog( "close" );
location.href='index.php';
      }
      }]
    });
  } );
</script>

檢測dialog是否為開啟狀態

alert( $( ".selector" ).dialog( "isOpen" ));

觸發錯誤 jquery ui: cannot call methods on dialog prior to initialization; attempted to call method 'isOpen'

以下列寫法修正:

alert( $( ".selector" ).dialog().dialog( "isOpen" ));

參考:http://stackoverflow.com/questions/3827830/jqueryui-uncaught-exception-cannot-call-methods

沒有留言:

張貼留言