jquery - 我可以简化 javascript 函数的调用方式吗?

标签 jquery

我在多个屏幕上内联执行以下内容:

tinyMCE.init({
    // General options
    mode : "specific_textareas",
    editor_selector : "mceEditor",
    theme: "advanced",
    plugins: "autolink,lists,spellchecker,pagebreak,style,layer,table,save,advhr,advimage,advlink,emotions,iespell,inlinepopups,insertdatetime,preview,media,searchreplace,print,contextmenu,paste,directionality,fullscreen,noneditable,visualchars,nonbreaking,xhtmlxtras,template",

    // Theme options
    theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,justifyright,justifyfull,|,styleselect,formatselect,fontselect,fontsizeselect",
    theme_advanced_buttons2: "cut,copy,paste,pastetext,pasteword,|,search,replace,|,bullist,numlist,|,outdent,indent,blockquote,|,undo,redo,|,link,unlink,anchor,image,cleanup,help,code,|,insertdate,inserttime,preview,|,forecolor,backcolor",
    theme_advanced_buttons3: "tablecontrols,|,hr,removeformat,visualaid,|,sub,sup,|,charmap,emotions,iespell,media,advhr,|,print,|,ltr,rtl,|,fullscreen",
    theme_advanced_buttons4: "insertlayer,moveforward,movebackward,absolute,|,styleprops,spellchecker,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,blockquote,pagebreak,|,insertfile,insertimage",
    theme_advanced_toolbar_location: "top",
    theme_advanced_toolbar_align: "left",
    theme_advanced_statusbar_location: "bottom",
    theme_advanced_resizing: true,

    // Skin options
    skin: "o2k7",
    skin_variant: "silver",

    // Example content CSS (should be your site CSS)
    content_css: "css/example.css",

    // Drop lists for link/image/media/template dialogs
    template_external_list_url: "js/template_list.js",
    external_link_list_url: "js/link_list.js",
    external_image_list_url: "js/image_list.js",
    media_external_list_url: "js/media_list.js",

    // Replace values for the template plugin
    template_replace_values: {
        username: "Some User",
        staffid: "991234"
    }
});

我想将其移至文件中然后调用它。有没有一种简单的方法可以做到这一点?

最佳答案

类似于Xander的答案,但我只会全局存储选项对象。

window.tinyMCEOptions = {
    // General options
    mode : "specific_textareas",
    /* Your other options here.
     * Store in your favorite .js file and link your page to it.
     */
}

然后调用tinyMCE.init,如下所示:

tinyMCE.init(window.tinyMCEOptions);

这样做的好处是它可以让您轻松更改选项:

window.tinyMCEOptions.content_css: 'css/different.css'
tinyMCE.init(window.tinyMCEOptions);

关于jquery - 我可以简化 javascript 函数的调用方式吗?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/9178617/

相关文章:

jquery - 自动完成选择重定向

javascript - 具有多个依赖项的多个 JavaScript 库

jquery - 具有视差、最大宽度技巧的流体图像无法按预期工作

javascript - jQuery.on() 在 WordPress 管理面板中不起作用

javascript - PHP 验证阻止表单发送

Javascript/jQuery : remove all non-numeric values from array

javascript - 使 div 像模态一样弹出

javascript - 围绕 jQuery 插件

javascript - jQuery GET 未成功

jquery - 如何通过名称而不是 ID 获取元素的值