【问题标题】:Is there any way to format style and text inside the Text Area?有没有办法在文本区域内格式化样式和文本?
【发布时间】:2015-05-14 07:17:17
【问题描述】:

您好,我有代码,我在文本区域内编写代码以获得如下格式。但我的问题是文本格式正确,以及如何在文本区域内放置相同的文本格式。

<input type="textarea">
<P align = center>
<B>About Salman Khan </B>
</P>
<P align = left>Salman Khan (pronunciation  born Abdul Rashid Salim Salman Khan on 27 December 1965)[5] is an INDIAN film actor and producer. He is cited in the media as one of the most commercially successful actors of Hindi cinema.
</P>
<P>
<ul>
	<li>Undertake our tasks and activities in utmost good faith, objectivity, transparency, competence, due care and professionalism.</li>
<li>Abide by the highest standards of politeness and good conduct.</li>
</ul>
</P>
</input>

【问题讨论】:

  • &lt;input type=textarea&gt; 不存在。使用&lt;textarea&gt;。但是你不能;不能在里面格式化文本。
  • 搜索所见即所得的编辑器
  • 尝试使用contenteditable div
  • 这是一个有效的标签 ?我认为代码是错误的......

标签: html css


【解决方案1】:

抱歉,您无法设置文本区域的样式。但是,似乎确实有一些解决方法可用。这是我发现的第一件事:

Format text in a <textarea>?

所以基本上你把你所有的内容放在一个 div 中并设置它的样式,让它像一个文本区域一样工作。在这里你可以看到我让它可滚动,让它可编辑,加上设置高度/宽度和边框。 (不需要设置,具体取决于您想要什么。)我认为这里最大的问题是不同的浏览器对文本区域的样式不同,因此可能没有真正简单的方式来设置它,所以它看起来就像一个原生的所有浏览器中的文本区域。

<div id='fake_textarea' style="overflow:scroll; height:100px; width:400px; border:solid; border-width:1px" contenteditable>
    <P align=center>
         <B>About Salman Khan </B>
    </P>
    <P align=left>
        Salman Khan (pronunciation  born Abdul Rashid Salim Salman Khan on 27 December 1965)[5] is an     INDIAN film actor and producer. He is cited in the media as one of the most commercially successful actors of Hindi cinema.
    </P>
    <P>
        <ul>
            <li>Undertake our tasks and activities in utmost good faith, objectivity, transparency, competence, due care and professionalism.</li>
            <li>Abide by the highest standards of politeness and good conduct.</li>
        </ul>
    </P>
</div>

请注意,这与您的代码相同,只是我将 input 标记替换为样式化的 div。

如果您需要在表单中使用此字段并且必须提交内容,请参阅上述答案中的帖子。这需要一些小工作。

【讨论】:

  • 我不明白你的意思。你能给我演示一下吗。我该怎么做。
猜你喜欢
  • 2012-08-25
  • 1970-01-01
  • 2021-11-27
  • 2013-04-16
  • 1970-01-01
  • 2014-07-06
  • 1970-01-01
  • 2020-12-12
  • 2023-04-10
相关资源
最近更新 更多