Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/72.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 每次保存文档时,换行符和段落都会加倍,或者在每次保存后添加额外的空格段落和换行符_Javascript_Jquery_Html_Asp.net_Ckeditor - Fatal编程技术网

Javascript 每次保存文档时,换行符和段落都会加倍,或者在每次保存后添加额外的空格段落和换行符

Javascript 每次保存文档时,换行符和段落都会加倍,或者在每次保存后添加额外的空格段落和换行符,javascript,jquery,html,asp.net,ckeditor,Javascript,Jquery,Html,Asp.net,Ckeditor,您好,我已经在我的asp.net和vb.net web应用程序中实现了ckeditor。经过一番努力,它工作得很好 但每次保存后都会添加大量换行符和段落(特别是从word文件中复制和粘贴)。提交页面后,编辑器将在html中放置额外的 如果有一个换行符,则添加4个换行符。如果我屈服 xxx<br>yyy xxxyyy 在提交之后,它变得越来越重要 xxx<br/><br/><br/><br/<br/><br/>yy

您好,我已经在我的asp.net和vb.net web应用程序中实现了ckeditor。经过一番努力,它工作得很好

但每次保存后都会添加大量换行符和段落(特别是从word文件中复制和粘贴)。提交页面后,编辑器将在html中放置额外的

如果有一个换行符,则添加4个换行符。如果我屈服

xxx<br>yyy 
xxx
yyy
在提交之后,它变得越来越重要

xxx<br/><br/><br/><br/<br/><br/>yyy
xxx


您可以通过以下方式避免:

config.autoParagraph = false;


有关更多信息,请参见CKEditor中的,我通过在config.js文件中添加以下代码行解决了这个问题

CKEDITOR.editorConfig = function (config) {
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
CKEDITOR.on('instanceReady', function (ev) {
    var writer = ev.editor.dataProcessor.writer;
    // The character sequence to use for every indentation step.
    writer.indentationChars = '  ';

    var dtd = CKEDITOR.dtd;
    // Elements taken as an example are: block-level elements (div or p), list items (li, dd), and table elements (td, tbody).
    for (var e in CKEDITOR.tools.extend({}, dtd.$block, dtd.$listItem, dtd.$tableContent)) {
        ev.editor.dataProcessor.writer.setRules(e, {
            // Indicates that an element creates indentation on line breaks that it contains.
            indent: false,
            // Inserts a line break before a tag.
            breakBeforeOpen: false,
            // Inserts a line break after a tag.
            breakAfterOpen: false,
            // Inserts a line break before the closing tag.
            breakBeforeClose: false,
            // Inserts a line break after the closing tag.
            breakAfterClose: false
        });
    }

    for (var e in CKEDITOR.tools.extend({}, dtd.$list, dtd.$listItem, dtd.$tableContent)) {
        ev.editor.dataProcessor.writer.setRules(e, {
            indent: true,
        });
    }



});
}
如果有人像我一样面临同样的问题,只需复制上述代码并将其粘贴到ckeditor文件夹的config.js文件中


谢谢你的回答。您的帮助很大

您的问题不在于CKEditor或其配置


相反,您应该查看服务器代码并删除对nl2br的调用

请共享粘贴
xxx
yyy后生成的源代码
我已更新了问题并在其中添加了源代码。请查看并帮助我添加到文件的可能副本我的config.js文件如下所示,但不起作用。仍在添加换行符和段落ckeditor.editorConfig=function(config){config.autoParagraph=false;};你好我试过这些解决办法。。但结果仍然是一样的。为了澄清首次复制和粘贴时我们没有看到这种行为,问题只在后续编辑/保存时出现。还有什么建议吗?我不确定你是否正确阅读了这篇文章。我解决了问题,并提供了解决方案。我们的服务器没有任何问题。config.js文件中需要一些定制。就是这样。您所做的是删除CKEditor用于格式化输出的所有换行符。服务器上的那些换行符被替换为

,这就是您出现问题的原因。
$('#' + '<%= btnSave.ClientID%>').mousedown(function () {
    for (var i in CKEDITOR.instances) {
        CKEDITOR.instances[i].updateElement();
    }
});
<p><strong>Working Log</strong></p>
<ol style="list-style-type:lower-roman">
   <li>1<sup>st</sup> Week : Introduction
    <ul style="list-style-type:circle">
        <li>Discovered the location of the website</li>
        <li>Started familiarise with the websites and portal.</li>
    </ul>
   </li>
</ol>
        <p><strong>Working Log</strong></p>
    <p>&nbsp;</p>
    <p>&nbsp;</p>
    <ol style="list-style-type:lower-roman"><br />
        <li>1<sup>st</sup> Week : Introduction<br />
          &nbsp;
        <ul style="list-style-type:circle"><br />
            <li>Discovered the location of the website</li>
            <br />
            <li>Started familiarise with the websites and portal.</li>
           <br />
           <br />
           &nbsp;
        </ul>
        </li>
           <br />
         <br />
        &nbsp;
         </ol>
        <p>&nbsp;</p>
        <p>&nbsp;</p>
config.autoParagraph = false;
config.enterMode = CKEDITOR.ENTER_BR;
CKEDITOR.on('txtDescription', function (ev) {
        ev.editor.dataProcessor.writer.setRules('br',
         {
             indent: false,
             breakBeforeOpen: false,
             breakAfterOpen: false,
             breakBeforeClose: false,
             breakAfterClose: false
         });
    });

config.enterMode = CKEDITOR.ENTER_BR;
config.shiftEnterMode = CKEDITOR.ENTER_BR;
CKEDITOR.editorConfig = function (config) {
// Define changes to default configuration here. For example:
// config.language = 'fr';
// config.uiColor = '#AADC6E';
CKEDITOR.on('instanceReady', function (ev) {
    var writer = ev.editor.dataProcessor.writer;
    // The character sequence to use for every indentation step.
    writer.indentationChars = '  ';

    var dtd = CKEDITOR.dtd;
    // Elements taken as an example are: block-level elements (div or p), list items (li, dd), and table elements (td, tbody).
    for (var e in CKEDITOR.tools.extend({}, dtd.$block, dtd.$listItem, dtd.$tableContent)) {
        ev.editor.dataProcessor.writer.setRules(e, {
            // Indicates that an element creates indentation on line breaks that it contains.
            indent: false,
            // Inserts a line break before a tag.
            breakBeforeOpen: false,
            // Inserts a line break after a tag.
            breakAfterOpen: false,
            // Inserts a line break before the closing tag.
            breakBeforeClose: false,
            // Inserts a line break after the closing tag.
            breakAfterClose: false
        });
    }

    for (var e in CKEDITOR.tools.extend({}, dtd.$list, dtd.$listItem, dtd.$tableContent)) {
        ev.editor.dataProcessor.writer.setRules(e, {
            indent: true,
        });
    }



});
}