2012-05-10 121 views
1

只要單擊Tinymce編輯器的「保存」按鈕,表單就會提交給服務器。我需要停止表單提交。我搜查了很多,但找不到任何解決方案。這裏是我的代碼,如何在單擊「保存」按鈕時停止提交jquery.TinyMCE

$('textarea.tinymce').tinymce({ 
    paste_retain_style_properties : "margin, padding, width, height, font-size, font-weight, font-family, color, text-align, ul, ol, li, text-decoration, border, background, float, display", 
    script_url : path_global+'/js/TinyMCE/tiny_mce.js', 
    valid_children : "+body[style]", 
    theme : "advanced", 
    plugins : "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_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,|,cite,abbr,acronym,del,ins,attribs,|,visualchars,nonbreaking,template,pagebreak", 
    theme_advanced_toolbar_location : "top", 
    theme_advanced_toolbar_align : "left", 
    theme_advanced_statusbar_location : "bottom", 
    theme_advanced_resizing : true, 
    setup : function(ed) {   
     ed.onSaveContent.add(function(ed, l) { 
     }); 
    } 
}); 

更新:我已經找到了答案。挖掘源代碼我發現我可以在表單標籤上添加onsubmit =「return false」,這會阻止表單提交。

+0

從控件模板中刪除保存按鈕。這就是它的作用。 –

+0

@AndrewBarber,有沒有辦法通過ajax提交表單? – user960567

+0

這將是一個不同的問題,不是嗎? (我認爲其中一個已經被問及在這裏回答)。 –

回答

2

我找到了答案。挖掘來源我發現,我可以添加,

onsubmit = "return false" 

在表單標籤將停止表單提交。

+0

+1工作解決方案 – Thariama

+0

感謝您的答案。現在看起來很明顯,但我甚至嘗試使用jQuery捕獲表單提交併使用$('#element')中止它。submit(function(){return false;});但沒有工作,我瘋了。 – Pere

相關問題