NiceEdit点击问题

时间:2016-03-10 11:50:44

标签: javascript html nicedit

我在winforms中使用了nicEditor,加载了一个Web浏览器并在其中加载了nicEditor。默认情况下,当编辑器加载时,我在编辑器中间单击,焦点不会转到nicEditor。但是,如果我在编辑器的开头单击,焦点将设置为编辑器。以下是我的HTML文件代码。

<html>
<head>
    <script type="text/javascript">
        var myInstance = "";
        function GetContent() {
            //window.alert(""+myInstance);
            //var content = tinyMCE.get('tinyMceEditor').getContent();
            //content = content.replace("<body>", "<body style=\"font-size:10px;\">");
            //var content = nicEditors.get('area3').getContent();
            var content = myInstance.instanceById('editor').getContent();
            //window.alert(myInstance.instanceById('editor').getContent());
            return content;
        }
        function SetContent(htmlContent) {
            setTimeout(function () {
                //window.alert(htmlContent);
                //nicEditors.get('area3').setContent(htmlContent);
                myInstance.instanceById('editor').setContent(htmlContent);

                if (htmlContent == undefined || htmlContent == '')
                    myInstance.instanceById('editor').setContent('');

                //tinyMCE.get('tinyMceEditor').readOnly = true;
            }, 100);
        }     
    </script>
   <script type="text/javascript" src="jscripts/nicEdit.js"></script>
    <script type="text/javascript">

        bkLib.onDomLoaded(function () {
            //myInstance = new nicEditor().panelInstance('editor');
            myInstance = new nicEditor({ maxHeight: 388 }).panelInstance('editor');

            //nicEditors.allTextAreas() 
        });
</script>
</head>
<body style="margin-top: 0px; margin-left: 0px;">
    <div id="sample">
        <textarea id="demo" cols="50" id="editor" name="editor" style="width:295px;" >
        </textarea>
    </div>
</body>
</html>

请帮忙。

2 个答案:

答案 0 :(得分:0)

它以这种方式工作。 但是我没有使用下面的脚本得到你想要做的事情。

<script type="text/javascript">

        bkLib.onDomLoaded(function () {
            //myInstance = new nicEditor().panelInstance('editor');
            myInstance = new nicEditor({ maxHeight: 388 }).panelInstance('editor');

            //nicEditors.allTextAreas() 
        });
</script>

这是我简单的HTML。现在让我知道你想要做什么。

<html>
    <head>
    </head>
    <body style="margin-top: 0px; margin-left: 0px;">
        <div id="sample">
            <script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script>
            <script type="text/javascript">
                //<![CDATA[
                bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
                //]]>

            </script>
            <textarea id="demo" cols="50" id="editor" name="editor" style="width:295px;" >
            </textarea>
        </div>
    </body>
</html>

答案 1 :(得分:0)

寻找这样的事情, 如果我在任何地方都错了,请告诉我。

<html>
    <head>
    <script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
    </head>
    <style type="text/css">
        .heightClass {
            min-height: 338px !important;
        }
        </style>
    <body style="margin-top: 0px; margin-left: 0px;">
        <div id="sample">
            <script type="text/javascript" src="http://js.nicedit.com/nicEdit-latest.js"></script>
            <script type="text/javascript">
                //<![CDATA[
                bkLib.onDomLoaded(function() { nicEditors.allTextAreas() });
                //]]>
                $(document).on("focus" , ".nicEdit-selected" , function () {
                   var parentTag = $( this ).css("height" , "338px");
                   //$( this ).addClass("heightClass");
                   //alert(parentTag);
                });
            </script>
            <textarea id="demo" cols="50" id="editor" name="editor" style="width:295px;" >
            </textarea>
        </div>
    </body>
</html>