2012-01-09 42 views
2

我有一個由文本行組成的字符串。我想輸入這些行到一些CSS樣式的textarea(例如改變一些線的顏色)。如何才能做到這一點?textarea Wicket的樣式文本

回答

1

使用tinymce編輯器。 http://www.tinymce.com/
或者你可以使用任何類型的一個Javascript所見即所得編輯器

添加TinyMCE的頁面中,

<script type="text/javascript" src="<your installation path>/tiny_mce/tiny_mce.js"></script> 

<script type="text/javascript"> 
tinyMCE.init({ 
    // General options 
    mode : "textareas", 
    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" 
    } 
}); 
</script> 
+0

我仍然推Wicketstuff TinyMCE包。不一定更容易,但更適合Wicket應用程序。 – jbrookover 2012-01-10 09:55:25

1

TinyMCE確實做在編輯器中渲染CSS和其它標記的一個相當不錯的工作。

爲了方便Wicket使用,我建議使用org.wicketstuff.tinymce-parent包。開發/源代碼位於GitHub中,實際版本位於公共Maven存儲庫中。

然後,您可以使用標準的Wicket TextArea組件,並將TinyMCE行爲添加到它,而不是直接與javascript混淆。

其中一個缺點是,雖然TinyMCE非常成熟,但它也有一些不明顯的錯誤。如果可能的話,最好保持簡單。