在< textarea&gt ;?中格式化文本 [英] Format text in a <textarea>?

查看:81
本文介绍了在< textarea&gt ;?中格式化文本的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

Textareas是伟大的,因为一些内置的功能(滚动条)。如何格式化< textarea>

Textareas are great because of some built in functionality (scrollbars). How can I format <spans> of text inside of the <textarea>?

推荐答案

如果您需要自定义您的textarea,使用另一个元素(如DIV)重现其行为与 contenteditable 属性。

If you need to customize your textarea, reproduce its behavior using another element (like a DIV) with the contenteditable attribute.

这是更可定制的,更现代的方法,textarea只是纯文本内容,而不是丰富的内容。

It's more customizable, and a more modern approach, textarea is just for plain text content, not for rich content.

<div id='fake_textarea' contenteditable></div>

滚动条可以使用CSS overflow属性重现。

The scrollbars can be reproduced with the CSS overflow property.

你可以使用这种假的textarea格式正常,例如:如果你必须通过POST方法提交它的内容,你可以做一些类似的事情: / p>

You can use this fake textarea in a form normally, i.e: if you have to submit its content through POST method, you could do something like(with jQuery):

<input type='hidden' id='fake_textarea_content' name='foobar' />

...

$('#your_form').submit(function()
{
  $('#fake_textarea_content').val($('#fake_textarea').html());
});

这篇关于在&lt; textarea&gt ;?中格式化文本的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆