2012-03-31 67 views
1

Telerik的HTML編輯器的內容有麻煩我有一個editor所建立起來如下:獲得使用jQuery

 EditorBuilder builder = context.Html.Telerik().Editor() 
                 .Name(ID) 
                 .Encode(false) 
                 .HtmlAttributes(new { style = string.Format("width:100%;height:{0}px", height) }) 
                 .Value(HttpUtility.HtmlEncode(value)); 

     return builder.ToHtmlString(); 

一切正常。我現在要做的是獲取編輯器的內容,以便用戶在另一個窗口中「預覽」它。經過一番搜索之後,我碰到了$find(<%=RadEditor.ClientID%>);,但我沒有使用這種形式生成編輯器(它在剃刀中)。

所以,我的問題是,如何使用jQuery獲取編輯器的內容? val()不起作用。

在此先感謝!

回答

2

Telerik使用jQuery數據() 方法存儲編輯器的內容。要訪問編輯器的內容使用下面的代碼:

var editor = $("#<your editor ID goes here>").data("tEditor"); 
alert(editor.value()); 

傳遞給jQuery的ID必須你傳遞給 Html.Telerik().Editor().Name()功能的ID相符。

上述代碼僅適用於您爲telerik編輯器設置了必要的腳本 。請參閱telerik client side api documentation

+0

感謝您的支持。我不完全確定爲什麼我錯過了你鏈接的那個頁面,但我管理它! – 2012-03-31 15:16:30