简体   繁体   English

.net c#asp.net使Textbox文本的一部分变为粗体

[英].net c# asp.net make part of Textbox text bold

I have a .NET C#/Aspx web application in which users fill in fields and the resulting form is emailed out. 我有一个.NET C#/ Aspx Web应用程序,用户在其中填写字段,并通过电子邮件发送结果表单。 I have a requirement to allow users to highlight text and then make that text either bold or coloured or both. 我要求允许用户突出显示文本,然后将该文本设置为粗体或彩色或两者。

I have done a bit of searching on the net and found that javascript might be the best option. 我在网上做了一些搜索,发现javascript可能是最好的选择。 However, when the script inserts the html tags - it doesn't render within the textbox.I know this is a limitation of the asp.net textbox but is there anyway around this? 但是,当脚本插入html标签时 - 它不会在文本框中呈现。我知道这是asp.net文本框的限制但是无论如何都存在吗?

<script type="text/javascript"> 

function formatText(tag) {
    var selectedText = document.selection.createRange().text;

    if (selectedText != "") {
        var newText = "<" + tag + ">" + selectedText + "</" + tag + ">";
        document.selection.createRange().text = newText;
    }
} 

你需要一个像ckeditor这样的富文本编辑器。

Instead reinventing the wheel, take a look at a rich text editor, like for example TinyMCE you can strip it down, so the user only have the options like bold or italic. 而是重新发明轮子,看看富文本编辑器,例如TinyMCE,你可以将其剥离,因此用户只有粗体或斜体等选项。

More info how to create a simple example can be found here: 有关如何创建简单示例的更多信息,请访问:

Create a very simple TinyMCE wysiwyg Editor 创建一个非常简单的TinyMCE wysiwyg编辑器

Cannot be done in a Textbox.Go for any RichTextEditor. 不能在Textbox.Go中为任何RichTextEditor完成。 (CKEDITOR or CLEEDITOR) (CKEDITOR或CLEEDITOR)

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM