2

我正在使用nicedit.js将我的textarea转换为html编辑器,当我直接调用页面时没有问题,但是当我通过ajax调用或调用jquery选项卡下的页面时,编辑器页面不加载但弹出错误,

错误:'null' 为 null 或不是对象

我声明我的文本区域如下

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

提前致谢

4

3 回答 3

6

在破解我的头之后,我终于找到了解决方案,所以当通过 ajax 调用包含编辑器的页面时,只需将 textarea 声明为 new nicEditor().panelInstance('content');

不是 bkLib.onDomLoaded(function() { new nicEditor().panelInstance('content'); }

于 2011-03-29T03:55:28.853 回答
3

我用

new nicEditors.allTextAreas;

代替

bkLib.onDomLoaded(nicEditors.allTextAreas);
于 2012-09-10T13:02:56.153 回答
0

基本上,如果您使用 ASP.NET 和更新面板,您可以复制粘贴代码。注意:不要忘记为您更改 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;

设置文本区域值:

hdnNicEdit.value = "i am setting text into textarea"

更多信息:https ://dotnetdaily.net/web-development/tutorials/aspdotnet/nicedit-work-update-panel-asp-net

于 2018-03-14T23:56:43.747 回答