簡體   English   中英

TypeError:CKEDITOR.instance未定義-對象實例的測試給出錯誤

[英]TypeError: CKEDITOR.instance is undefined — Test for object instance gives error

情況:在jQuery對話框中調用CKEDITOR(這里有很多挑戰)。 我的特定問題是,當我測試CKEDITOR實例的存在時,總是會引發錯誤。

瀏覽器測試:Firefox 21,IE 9,Safari 5.1.7

錯誤:錯誤:TypeError:CKEDITOR.instance未定義

測試CKEDITOR實例的所有這些方式總是拋出javascript錯誤:

if(!CKEDITOR.instance ['editor']){

如果(CKEDITOR.instance [ '編輯']){

if(!typeof CKEDITOR.instance ['editor'] ==“未定義”){

if(!typeof(CKEDITOR.instance ['editor'])==“未定義”){

if(typeof CKEDITOR.instance ['editor']!=“未定義”){

if(typeof CKEDITOR.instance ['editor']!==“未定義”){

if(typeof CKEDITOR.instance ['editor'] ===“未定義”){

當然,在發布這篇文章之前,我仔細檢查了StackOverflow。 我已經嘗試了StackOverflow上建議的“ typeof”和“ undefined”的每種組合。

如果在測試實例是否存在錯誤時如何檢測對象實例的存在? 一個難題!

CKEDITOR.instance

但:

CKEDITOR.instances

它始終存在-無需測試。

您正在測試錯誤的對象(在這種情況下為對象屬性)。 instance未定義,因此您必須先檢查instance是否已定義,然后再測試其屬性之一。

if ( CKEDITOR.instance && CKEDITOR.instance['editor'] ) {

或者,如果您想知道何時未定義,

if ( !CKEDITOR.instance || !CKEDITOR.instance['editor'] ) {

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM