Drop down menu nicEdit不显示选定的字体大小和字体系列

Drop down menu nicEdit不显示选定的字体大小和字体系列,drop-down-menu,fonts,nicedit,Drop Down Menu,Fonts,Nicedit,我已将nicEdit添加到代码中,但不知何故,当我选择字体大小和系列时,nicEdit不会显示所做的选择。有什么出路和可能的解决方案吗?我稍微调整了js文件以获得ans。如果一个函数看起来足够近,那么所有函数都在那里。 查找var nicEditorSelect=bkClass.extend({)中的update函数。当任何下拉框的值发生更改时,将调用此函数。elm传递的参数是值。您可以通过console.log查看该值 this.setDisplay(elm) 将为显示设置所选值。基于最新版

我已将nicEdit添加到代码中,但不知何故,当我选择字体大小和系列时,nicEdit不会显示所做的选择。有什么出路和可能的解决方案吗?

我稍微调整了js文件以获得ans。如果一个函数看起来足够近,那么所有函数都在那里。 查找
var nicEditorSelect=bkClass.extend({
)中的
update
函数。当任何下拉框的值发生更改时,将调用此函数。
elm
传递的参数是值。您可以通过console.log查看该值

this.setDisplay(elm)
将为显示设置所选值。

基于最新版本,以下是我改进选择选项的解决方案。我已修复了要显示的显示文本,但为每个选项添加了一个新的显示文本作为第三个数组参数,以避免出现巨大的标题1显示文本等。我还调整了宽度

/* START CONFIG */
var nicSelectOptions = {
    buttons: {
        'fontFormat' : {name : __('Select Font Format'), type : 'nicEditorFontFormatSelect', command : 'formatBlock'},
        'fontFamily': { name: __('Select Font Family'), type: 'nicEditorFontFamilySelect', command: 'fontname' },
        'fontSize' : {name : __('Select Font Size'), type : 'nicEditorFontSizeSelect', command : 'fontsize'}
    }
};
/* END CONFIG */
var nicEditorSelect = bkClass.extend({

    construct : function(e, buttonName, options, nicEditor) {
        this.options = options.buttons[buttonName];
        this.elm = e;
        this.ne = nicEditor;
        this.name = buttonName;
        this.selOptions = new Array();

        this.buttonWidth = buttonName === "fontSize" ? 50 : 100;

        this.margin = new bkElement('div').setStyle({ 'float': 'left', margin: '2px 1px 0 1px' }).appendTo(this.elm);
        this.contain = new bkElement('div').setStyle({ width: this.buttonWidth + 'px', height: '20px', cursor: 'pointer', overflow: 'hidden' }).addClass('selectContain').addEvent('click', this.toggle.closure(this)).appendTo(this.margin);
        this.items = new bkElement('div').setStyle({ overflow: 'hidden', zoom: 1, border: '1px solid #ccc', paddingLeft: '3px', backgroundColor: '#fff' }).appendTo(this.contain);
        this.control = new bkElement('div').setStyle({ overflow: 'hidden', 'float': 'right', height: '18px', width: '16px' }).addClass('selectControl').setStyle(this.ne.getIcon('arrow', options)).appendTo(this.items);
        this.txt = new bkElement('div').setStyle({ overflow: 'hidden', 'float': 'left', width: this.buttonWidth - 22 + 'px', height: '16px', marginTop: '1px', fontFamily: 'sans-serif', textAlign: 'center', fontSize: '12px' }).addClass('selectTxt').appendTo(this.items);

        if (!window.opera) {
            this.contain.onmousedown = this.control.onmousedown = this.txt.onmousedown = bkLib.cancelEvent;
        }

        this.margin.noSelect();

        this.ne.addEvent('selected', this.enable.closure(this)).addEvent('blur', function(event) {
            this.disable.closure(this);
            this.setDisplay(elm);
        });

        this.disable();
        this.init();

    },

    disable : function() {
        this.isDisabled = true;
        this.close();
        this.contain.setStyle({opacity : 0.6});
    },

    enable : function(t) {
        this.isDisabled = false;
        this.close();
        this.contain.setStyle({opacity : 1});
    },

    setDisplay : function(txt) {
        this.txt.setContent(txt);
    },

    toggle : function() {
        if(!this.isDisabled) {
            (this.pane) ? this.close() : this.open();
        }
    },

    open : function() {
        this.pane = new nicEditorPane(this.items, this.ne, { minWidth: this.buttonWidth - 2 + 'px', padding: '0px', borderTop: 0, borderLeft: '1px solid #ccc', borderRight: '1px solid #ccc', borderBottom: '0px', backgroundColor: '#fff' });

        for(var i=0;i<this.selOptions.length;i++) {
            var opt = this.selOptions[i];
            var itmContain = new bkElement('div').setStyle({ overflow: 'hidden', borderBottom: '1px solid #ccc', minWidth: this.buttonWidth - 2 + 'px', textAlign: 'left', overflow: 'hidden', cursor: 'pointer' });
            var itm = new bkElement('div').setStyle({padding : '0px 4px'}).setContent(opt[1]).appendTo(itmContain).noSelect();
            itm.addEvent('click',this.update.closure(this,opt[0],opt[2])).addEvent('mouseover',this.over.closure(this,itm)).addEvent('mouseout',this.out.closure(this,itm)).setAttributes('id',opt[0]);
            this.pane.append(itmContain);
            if(!window.opera) {
                itm.onmousedown = bkLib.cancelEvent;
            }
        }
    },

    close : function() {
        if(this.pane) {
            this.pane = this.pane.remove();
        }   
    },

    over : function(opt) {
        opt.setStyle({backgroundColor : '#ccc'});           
    },

    out : function(opt) {
        opt.setStyle({backgroundColor : '#fff'});
    },


    add : function(k,v,d) {
        this.selOptions.push(new Array(k,v,d)); 
    },

    update: function (elm, elmTxt) {
        this.ne.nicCommand(this.options.command, elm);
        this.setDisplay(elmTxt);
        this.close();   
    }
});

var nicEditorFontFamilySelect = nicEditorSelect.extend({
    sel: { 'arial': 'Arial', 'comic sans ms': 'Comic&nbsp;Sans', 'courier new': 'Courier&nbsp;New', 'georgia': 'Georgia', 'helvetica': 'Helvetica', 'impact': 'Impact', 'times new roman': 'Times', 'trebuchet ms': 'Trebuchet', 'verdana': 'Verdana' },

    init : function() {
        this.setDisplay('Font');
        for(itm in this.sel) {
            this.add(itm, '<font face="' + itm + '">' + this.sel[itm] + '</font>', '<font face="' + itm + '">' + this.sel[itm] + '</font>');
        }
    }
});

var nicEditorFontSizeSelect = nicEditorSelect.extend({
    sel: { 1: '8', 2: '10', 3: '12', 4: '14', 5: '18', 6: '24' },
    init: function () {
        this.setDisplay('Size');
        for (itm in this.sel) {
            this.add(itm, '<font size="' + itm + '">' + this.sel[itm] + '</font>', this.sel[itm]);
        }
    }
});

var nicEditorFontFormatSelect = nicEditorSelect.extend({
    sel: { 'p': 'Paragraph', 'h1': 'Heading&nbsp;1', 'h2': 'Heading&nbsp;2', 'h3': 'Heading&nbsp;3', 'h4': 'Heading&nbsp;4', 'h5': 'Heading&nbsp;5', 'h6': 'Heading&nbsp;6', 'pre': 'Pre' },

    init : function() {
        this.setDisplay('Style');
        for(itm in this.sel) {
            var tag = itm.toUpperCase();
            this.add('<' + tag + '>', '<' + itm + ' style="padding: 0px; margin: 0px;">' + this.sel[itm] + '</' + tag + '>', this.sel[itm]);
        }
    }
});


是的,我也在寻找解决方案。我查看了更新:函数(elm)一行{-如果我提醒elm iam获取值,现在如何传递值以使所选值保持不变。我尝试了,this.options.command.val=elm,但没有任何效果oops!我忘记添加最后一步。ans已被修改。+1感谢您的回答。它适用于字体大小和字体系列。它不适用于字体格式。我实际上正在查看ing仅针对大小和系列。我没有尝试过字体格式。但请放心,这里只处理下拉列表。请尝试elm和调用。我在下面的回答中对此进行了扩展。
/* START CONFIG */

var nicEditorConfig = bkClass.extend({
    buttons : {
        'bold' : {name : __('Click to Bold'), command : 'Bold', tags : ['B','STRONG'], css : {'font-weight' : 'bold'}, key : 'b'},
        'italic' : {name : __('Click to Italic'), command : 'Italic', tags : ['EM','I'], css : {'font-style' : 'italic'}, key : 'i'},
        'underline' : {name : __('Click to Underline'), command : 'Underline', tags : ['U'], css : {'text-decoration' : 'underline'}, key : 'u'},
        'left' : {name : __('Left Align'), command : 'justifyleft', noActive : true},
        'center' : {name : __('Center Align'), command : 'justifycenter', noActive : true},
        'right' : {name : __('Right Align'), command : 'justifyright', noActive : true},
        'justify' : {name : __('Justify Align'), command : 'justifyfull', noActive : true},
        'ol' : {name : __('Insert Ordered List'), command : 'insertorderedlist', tags : ['OL']},
        'ul' :  {name : __('Insert Unordered List'), command : 'insertunorderedlist', tags : ['UL']},
        'subscript' : {name : __('Click to Subscript'), command : 'subscript', tags : ['SUB']},
        'superscript' : {name : __('Click to Superscript'), command : 'superscript', tags : ['SUP']},
        'strikethrough' : {name : __('Click to Strike Through'), command : 'strikeThrough', css : {'text-decoration' : 'line-through'}},
        'removeformat' : {name : __('Remove Formatting'), command : 'removeformat', noActive : true},
        'indent' : {name : __('Indent Text'), command : 'indent', noActive : true},
        'outdent' : {name : __('Remove Indent'), command : 'outdent', noActive : true},
        'hr' : {name : __('Horizontal Rule'), command : 'insertHorizontalRule', noActive : true}
    },
    iconsPath : '../nicEditorIcons.gif',
    buttonList: ['save', 'bold', 'italic', 'underline', 'left', 'center', 'right', 'justify', 'ol', 'ul', 'fontFormat', 'fontFamily', 'fontSize', 'indent', 'outdent', 'image', 'upload', 'link', 'unlink', 'forecolor', 'bgcolor'],
    iconList : {"bgcolor":1,"forecolor":2,"bold":3,"center":4,"hr":5,"indent":6,"italic":7,"justify":8,"left":9,"ol":10,"outdent":11,"removeformat":12,"right":13,"save":24,"strikethrough":15,"subscript":16,"superscript":17,"ul":18,"underline":19,"image":20,"link":21,"unlink":22,"close":23,"arrow":25}

});
/* END CONFIG */