Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/383.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 - Fatal编程技术网

Javascript 下线逃逸不良

Javascript 下线逃逸不良,javascript,jquery,Javascript,Jquery,我正在尝试使用一个简单的所见即所得编辑器。JSLint称其“EOL逃逸不良”。由于我是javascript新手,我很难理解它的含义,因为我正在使用在线找到的代码。有谁能告诉我我应该做什么而不是以斜杠结束这行吗 以下是相关代码: /* *基于JQUERY RTE的所见即所得编辑器 */ //定义rte灯光插件 (函数($){ if(typeof$.fn.rte==“未定义”){ var默认值={ 内容\u css\u url:“rte.css”, 点网络按钮类:空, 最高高度:350 }; $.f

我正在尝试使用一个简单的所见即所得编辑器。JSLint称其“EOL逃逸不良”。由于我是javascript新手,我很难理解它的含义,因为我正在使用在线找到的代码。有谁能告诉我我应该做什么而不是以斜杠结束这行吗

以下是相关代码:

/*
*基于JQUERY RTE的所见即所得编辑器
*/
//定义rte灯光插件
(函数($){
if(typeof$.fn.rte==“未定义”){
var默认值={
内容\u css\u url:“rte.css”,
点网络按钮类:空,
最高高度:350
};
$.fn.rte=功能(选项){
$.fn.rte.html=函数(iframe){
返回iframe.contentWindow.document.getElementsByTagName(“正文”)[0].innerHTML;
};
//在元素迭代之前构建主选项
var opts=$.extend(默认值、选项);
//迭代并构造RTE
返回此。每个(函数(){
var textarea=$(此值);
var-iframe;
var元素_id=textarea.attr(“id”);
//启用设计模式
函数enableDesignMode(){
var content=textarea.val();
//Mozilla需要这个来显示插入符号
如果($.trim(内容)=''){
内容=“
”; } //已创建?显示/隐藏 if(iframe){ console.log(“已创建”); textarea.hide(); $(iframe.contents().find(“body”).html(content); $(iframe.show(); $(“#工具栏-”+元素_id).remove(); textarea.before(toolbar()); 返回true; } //出于兼容性原因,需要以这种方式创建 iframe=document.createElement(“iframe”); iframe.frameBorder=0; iframe.frameMargin=0; iframe.framePadding=0; iframe.height=200; if(textarea.attr('class'))iframe.className=textarea.attr('class'); if(textarea.attr('id'))iframe.id=element\u id; if(textarea.attr('name'))iframe.title=textarea.attr('name'); textarea.after(iframe); var css=“”; 如果(选择内容\u css\u url){ css=“”; } var doc=”“+css+“”+content+“”; tryEnableDesignMode(文档,函数(){ $(“#工具栏-”+元素_id).remove(); textarea.before(toolbar()); //隐藏文本区域 textarea.hide(); }); } 函数tryEnableDesignMode(文档,回调){ if(!iframe){ 返回false; } 试一试{ iframe.contentWindow.document.open(); iframe.contentWindow.document.write(doc); iframe.contentWindow.document.close(); }捕获(错误){ console.log(错误); } if(document.contentEditable){ iframe.contentWindow.document.designMode=“On”; 回调(); 返回true; }else if(document.designMode!==null){ 试一试{ iframe.contentWindow.document.designMode=“on”; 回调(); 返回true; }捕获(错误){ console.log(错误); } } setTimeout(函数(){ tryEnableDesignMode(文档,回调); }, 500); 返回false; } 功能禁用设计模式(提交){ var content=$(iframe.contents().find(“body”).html(); if($(iframe).is(“:visible”)){ text区域.val(内容); } 如果(提交!==true){ textarea.show(); $(iframe.hide(); } } //创建工具栏并将事件绑定到其元素 功能工具栏(){ 变量tb=$(“\ \ \ \ \

”; $('.bold',tb)。单击(函数(){ 格式化文本(“粗体”); 返回false; }); $('.italic',tb)。单击(函数(){ 格式化文本(“斜体”); 返回false; }); $('.unorderedlist',tb)。单击(函数(){ formatText('InsertunderedList'); 返回false; }); //.NET兼容性 如果(选择点网络按钮类){ var dot_net_button=$(iframe).parents('form').find(opts.dot_net_button_类); 点网络按钮。单击(函数(){ 禁用设计模式(真); }); //正则形式 }否则{ $(iframe).parents('form').submit(函数(){ 破坏
/*
 * WYSIWYG EDITOR BASED ON JQUERY RTE
 */

// define the rte light plugin
(function ($) {

    if (typeof $.fn.rte === "undefined") {

        var defaults = {
            content_css_url: "rte.css",
            dot_net_button_class: null,
            max_height: 350
        };

        $.fn.rte = function (options) {

            $.fn.rte.html = function (iframe) {
                return iframe.contentWindow.document.getElementsByTagName("body")[0].innerHTML;
            };

            // build main options before element iteration
            var opts = $.extend(defaults, options);

            // iterate and construct the RTEs
            return this.each(function () {
                var textarea = $(this);
                var iframe;
                var element_id = textarea.attr("id");

                // enable design mode
                function enableDesignMode() {

                    var content = textarea.val();

                    // Mozilla needs this to display caret
                    if ($.trim(content) === '') {
                        content = '<br />';
                    }

                    // already created? show/hide
                    if (iframe) {
                        console.log("already created");
                        textarea.hide();
                        $(iframe).contents().find("body").html(content);
                        $(iframe).show();
                        $("#toolbar-" + element_id).remove();
                        textarea.before(toolbar());
                        return true;
                    }

                    // for compatibility reasons, need to be created this way
                    iframe = document.createElement("iframe");
                    iframe.frameBorder = 0;
                    iframe.frameMargin = 0;
                    iframe.framePadding = 0;
                    iframe.height = 200;
                    if (textarea.attr('class')) iframe.className = textarea.attr('class');
                    if (textarea.attr('id')) iframe.id = element_id;
                    if (textarea.attr('name')) iframe.title = textarea.attr('name');

                    textarea.after(iframe);

                    var css = "";
                    if (opts.content_css_url) {
                        css = "<link type='text/css' rel='stylesheet' href='" + opts.content_css_url + "' />";
                    }

                    var doc = "<html><head>" + css + "</head><body class='frameBody'>" + content + "</body></html>";
                    tryEnableDesignMode(doc, function () {
                        $("#toolbar-" + element_id).remove();
                        textarea.before(toolbar());
                        // hide textarea
                        textarea.hide();

                    });

                }

                function tryEnableDesignMode(doc, callback) {
                    if (!iframe) {
                        return false;
                    }

                    try {
                        iframe.contentWindow.document.open();
                        iframe.contentWindow.document.write(doc);
                        iframe.contentWindow.document.close();
                    } catch (error) {
                        console.log(error);
                    }
                    if (document.contentEditable) {
                        iframe.contentWindow.document.designMode = "On";
                        callback();
                        return true;
                    } else if (document.designMode !== null) {
                        try {
                            iframe.contentWindow.document.designMode = "on";
                            callback();
                            return true;
                        } catch (error) {
                            console.log(error);
                        }
                    }
                    setTimeout(function () {
                        tryEnableDesignMode(doc, callback);
                    }, 500);
                    return false;
                }

                function disableDesignMode(submit) {
                    var content = $(iframe).contents().find("body").html();

                    if ($(iframe).is(":visible")) {
                        textarea.val(content);
                    }

                    if (submit !== true) {
                        textarea.show();
                        $(iframe).hide();
                    }
                }

                // create toolbar and bind events to it's elements
                function toolbar() {
                    var tb = $("<div class='rte-toolbar' id='toolbar-" + element_id + "'><div>\
                <p>\
                    <a href='#' class='bold'>Bold</a>\
                    <a href='#' class='italic'>Italic</a>\
                    <a href='#' class='unorderedlist'>List</a>\
                </p></div></div>");

                    $('.bold', tb).click(function () {
                        formatText('bold');
                        return false;
                    });
                    $('.italic', tb).click(function () {
                        formatText('italic');
                        return false;
                    });
                    $('.unorderedlist', tb).click(function () {
                        formatText('insertunorderedlist');
                        return false;
                    });

                    // .NET compatability
                    if (opts.dot_net_button_class) {
                        var dot_net_button = $(iframe).parents('form').find(opts.dot_net_button_class);
                        dot_net_button.click(function () {
                            disableDesignMode(true);
                        });
                        // Regular forms
                    } else {
                        $(iframe).parents('form').submit(function () {
                            disableDesignMode(true);
                        });
                    }

                    var iframeDoc = $(iframe.contentWindow.document);

                    var select = $('select', tb)[0];
                    iframeDoc.mouseup(function () {
                        setSelectedType(getSelectionElement(), select);
                        return true;
                    });

                    iframeDoc.keyup(function () {
                        setSelectedType(getSelectionElement(), select);
                        var body = $('body', iframeDoc);
                        if (body.scrollTop() > 0) {
                            var iframe_height = parseInt(iframe.style['height']);
                            if (isNaN(iframe_height)) iframe_height = 0;
                            var h = Math.min(opts.max_height, iframe_height + body.scrollTop()) + 'px';
                            iframe.style['height'] = h;
                        }
                        return true;
                    });
                    return tb;
                }

                function formatText(command, option) {
                    iframe.contentWindow.focus();
                    try {
                        iframe.contentWindow.document.execCommand(command, false, option);
                    } catch (e) {
                        //console.log(e)
                    }
                    iframe.contentWindow.focus();
                }

                function setSelectedType(node, select) {
                    while (node.parentNode) {
                        var nName = node.nodeName.toLowerCase();
                        for (var i = 0; i < select.options.length; i++) {
                            if (nName == select.options[i].value) {
                                select.selectedIndex = i;
                                return true;
                            }
                        }
                        node = node.parentNode;
                    }
                    select.selectedIndex = 0;
                    return true;
                }

                function getSelectionElement() {
                    if (iframe.contentWindow.document.selection) {
                        // IE selections
                        selection = iframe.contentWindow.document.selection;
                        range = selection.createRange();
                        try {
                            node = range.parentElement();
                        } catch (e) {
                            return false;
                        }
                    } else {
                        // Mozilla selections
                        try {
                            selection = iframe.contentWindow.getSelection();
                            range = selection.getRangeAt(0);
                        } catch (e) {
                            return false;
                        }
                        node = range.commonAncestorContainer;
                    }
                    return node;
                }

                // enable design mode now
                enableDesignMode();

            }); //return this.each

        }; // rte

    } // if

    $(".rte-zone").rte({});

})(jQuery);
"string 1" +
"string 2" +
"string 3"