2013-02-01 18 views
2

如果有某些字段使用htmleditor的要求。所以對於使用htmleditor的每個字段,我已經創建了一個編輯器模板,它使用jquery呈現htmleditor,並使用UIHint。mvc javascript多次

@model System.String 

<script type="text/javascript" src="~/Scripts/tiny_mce/tiny_mce.js"></script> 
<script type="text/javascript" language="javascript"> 
    tinyMCE.init({ 
     mode: "textareas", 
     theme: "advanced", 
     editor_selector: "htmlmarker", 
     theme_advanced_buttons1: "save,newdocument,|,bold,italic,underline,strikethrough,|,justifyleft,justifycenter,   justifyright,justifyfull,|,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: "hr,removeformat,visualaid,|,sub,sup", 

     theme_advanced_toolbar_location: "top", 
     theme_advanced_toolbar_align: "left" 

    }); 

</script> 
@Html.TextAreaFor(model => model, new {@class="htmlmarker" }) 

現在evreything作品不錯,但在執行時,我認爲我的源獲取jQuery的腳本會被引用,並呼籲多次爲使用UIHint各個領域。有沒有什麼機制來防止JavaScript代碼的重複?

回答

1

請勿將Javascript放入編輯器模板中,對於使用該模板的每個項目將執行

相反,把它放在一個單獨的JS文件,有一個叫上您的佈局JS文件,然後在頁面加載時,它會被執行一次,包括你已經在你的編輯模板分配類htmlmarker所有項目。