2013-05-31 105 views
0

我在頁面上使用cleditor創建一個RTE框,其下方有一個保存和取消按鈕。cleditor.selectedHTML():對象不支持屬性或方法

在我的保存按鈕的「onclick」功能。我調用了cirtitor對象的兩種方法,即:.select()和.selectedHTML()

.select()可以正常工作,但.selectedHTML()會產生「對象不支持屬性或方法」錯誤在我的瀏覽器(即)。

爲什麼我會收到此錯誤? .selectedHTML()方法確實存在。

見下面的代碼:

var $editor 
uab.crs_sum.prototype.render = function() { 

    var oJSON = {}; 
    var target = this.getTarget(); 
    var tmpHTML = []; 
    var chkOption = ""; 

tmpHTML = ["<textarea id='input' name='input'>This is some really great Content</textarea>"]; 
tmpHTML.push("<div><button style='width:6em'type='button' onclick='cancelEdit();'>Cancel</button><span style='width:3em'>&nbsp&nbsp&nbsp</span><button style='width:6em' type='button' onclick='saveEdit();'>Save</button></div>"); 
target.innerHTML = tmpHTML.join(""); 

$editor = $("#input").cleditor({ 
     "width":"100%" 
     }); 
} 


function saveEdit() { 
    $editor.select(); 
    alert($editor.selectedHTML()); // Error occurs on this line 
} 

回答

0

我不熟悉的.selectedHTML()方法,但什麼和我一起是隻使用標準的jQuery .val()方法。只需存儲工作副本即可恢復。

var $element = $('#input'), 
    currentVal = $element.val(); 

$editor = $element.cleditor({ 
     "width":"100%" 
})[0]; 


function saveEdit() { 
    alert($element.val()); 
} 

function cancelEdit() { 
    $element.val(currentVal); 
    $editor.updateFrame(); 
} 
0

僅供參考我遇到了同樣的問題,試圖使用selectedHTML()以下更改解決了我的問題。 ()函數返回數組。我只使用頁面上的單個編輯器嘗試過。

相關問題