Jquery 我可以简化javascript函数的调用方式吗?
我在许多屏幕上内联执行以下操作:Jquery 我可以简化javascript函数的调用方式吗?,jquery,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,emotio
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"
}
});
我想把它移到一个文件中,然后调用它。有没有一种简单的方法可以做到这一点?在
base.js
中:
window.pageinit = function(){
tinyMCE.init({
/* ... your initialization code ... */
});
}
<script type="text/javascript">
pageinit();
</script>
在引用base.js
的页面中:
window.pageinit = function(){
tinyMCE.init({
/* ... your initialization code ... */
});
}
<script type="text/javascript">
pageinit();
</script>
pageinit();
与的答案类似,但我只全局存储options对象
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);
属于:codereview.stackexchange.com谢谢。我从来没见过“窗户”这个词。它做什么?窗口是浏览器中的全局对象。这是定义
文档
对象和其他全局对象的地方。。。