day*_*mer 17 html formatting google-app-engine textarea
题:
PS我是Web开发领域的新手,也是我的第一个项目
谢谢
iai*_*ain 10
一个文本框就像wordpad,你不能格式化它,如果你从word或任何其他格式化文本粘贴它将擦除所有格式,你将只留下文本.
你需要在文本区域添加一个编辑器,我使用TinyMCE,但是还有很多其他的.
要实现,您需要在Web目录中拥有所有源(可以从TinyMCE获得).
以下是您可以尝试的示例:
将其添加到页面的head部分:
<script language="javascript" type="text/javascript" src="/js/tiny_mce/tiny_mce.js"></script>
<script language="javascript" type="text/javascript">
tinyMCE.init({
theme : "advanced",
mode: "exact",
elements : "elm1",
theme_advanced_toolbar_location : "top",
theme_advanced_buttons1 : "bold,italic,underline,strikethrough,separator,"
+ "justifyleft,justifycenter,justifyright,justifyfull,formatselect,"
+ "bullist,numlist,outdent,indent",
theme_advanced_buttons2 : "link,unlink,anchor,image,separator,"
+"undo,redo,cleanup,code,separator,sub,sup,charmap",
theme_advanced_buttons3 : "",
height:"350px",
width:"600px"
});
</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>
Run Code Online (Sandbox Code Playgroud)
然后调用textarea:
<textarea name="content" style="width:100%">YOUR TEXT HERE</textarea>
Run Code Online (Sandbox Code Playgroud)
注意:您需要下载并在您的目录中拥有js文件 <script language="javascript" type="text/javascript" src="/js/tiny_mce/tiny_mce.js"></script>
希望这可以帮助!
如果您希望某人能够格式化其文本(例如,使用所见即所得的粗体按钮等),但是如果您希望能够接受预先格式化的HTML(例如,从其他HTML来源复制和粘贴),则无法解决这种情况例如网页),则可以执行以下操作:
<form ...>
<label>Paste your HTML in the box below</label>
<textarea style='display:none' id='foo'></textarea>
<div id='htmlsource' contenteditable style='border:solid 1px black;padding:1em;width:100%;min-height:2em;' ></div>
<input type='submit' />
</form>
<script>
jQuery(function(){
jQuery('form').submit( function(e) {
jQuery('textarea').val( jQuery('#htmlsource').html() );
});
});
</script>
Run Code Online (Sandbox Code Playgroud)
这使用了一个contenteditable
div
元素,您可以将其设置为看起来像输入框的格式,并接受粘贴的HTML,而隐藏的元素textarea#foo
将在提交表单之前用粘贴的HTML填充。
请注意,这不是一个可访问的解决方案。
归档时间: |
|
查看次数: |
32326 次 |
最近记录: |