题
我正在使用nicedit.js将我的textarea转换为html编辑器,当我直接调用页面时,没有问题,但是当我通过ajax呼叫或呼叫页面致电,jQuery选项卡,编辑器页面负载但流行错误错误,
错误:'null'为null或不是对象
我声明了我的textarea,如下所示
bkLib.onDomLoaded(function() {
new nicEditor({iconsPath :'<%=request.getContextPath()%>/images/nicEditorIcons.gif',
maxHeight:345,
buttonList : ['save','bold','italic','underline','left','center','right','justify','ol','ul','fontSize','fontFamily','fontFormat','indent','outdent','image','upload','link','unlink','forecolor','xhtml']}).panelInstance('content');
});
.
任何人都使用nicedit与ajax
提前感谢
解决方案
破解我的头后,最后我找到了解决方案,所以当通过AJAX包含编辑器的呼叫页面时,只是声明textarea 新的尼迪特托斯()。PanelInstance('内容');
不是 bklib.ondomloaded(function(){ 新的尼迪特托斯()。PanelInstance('内容'); }
其他提示
我使用
new nicEditors.allTextAreas;
.
而不是
bkLib.onDomLoaded(nicEditors.allTextAreas);
. 基本上如果您正在使用ASP.NET和UPDATE面板,可以复制代码。注意:不要忘记更改您的TextArea ID。
<script type="text/javascript">
//hdnNicEdit: it is a hiddenfield in ASP page.
function SaveContent() {
$("#<%=hdnNicEdit.ClientID %>").val($(".nicEdit-main").html());
}
function pageLoad() {
$(function () {
new nicEditor().panelInstance('here your textarea id');
$(".nicEdit-main").html($("#<%=hdnNicEdit.ClientID %>").val());
})
}
</script>
.
ASP页面:
.
<textarea ID="YOUR TEXTAREA ID" class="form-control" runat="server"></textarea>
<asp:HiddenField ID="hdnNicEdit" runat="server" />
注意:您需要添加:OnClientClick=“saveContent();”进入按钮,您可以保存Nicedit Textarea值。
服务器端。
获取文本区域值:
.string textAreaValue = hdnNicEdit.value;
设置textarea值:
.hdnNicEdit.value = "i am setting text into textarea"
更多信息: https://dotnetdaily.net/web-development/tutorials/aspdotnet/nicedit-work-update-panel-asp-net