简体   繁体   English

Textarea类型特殊字符

[英]Textarea type special characters

In a textarea I want the user to be able to press the letters on their keyboard and type 𝒜ℬ𝒞𝒟 etc. (so typing the &ascr ; &bscr ; special characters) 在textarea中,我希望用户能够按下键盘上的字母并键入𝒜ℬ𝒞𝒟等(因此键入𝒶𝒷特殊字符)

Is there anyway to do this? 反正有没有这样做? And have the user freely being able to edit the characters like in a normal textarea. 并且让用户可以自由地编辑正常文本区域中的字符。

The user will be able to click to select a style (which sets my var style integer) and the letters will be a different style like 𝔄𝔅ℭ𝔇 (&Afr ; &Bfr ; &Cfr ; etc.) 用户可以单击以选择样式(设置我的var样式整数),字母将是不同的样式,如𝔄𝔅ℭ𝔇(𝔄𝔅ℭ等)

What I want to achieve at the end is the user typing a paragraph, then the text will appear formatted in that way in the textarea, they could switch styles in between. 我想在最后实现的是用户输入一个段落,然后文本将在textarea中以这种方式显示格式,他们可以在两者之间切换样式。 Then they will be able to copy the text / save it as a .html file. 然后他们将能够复制文本/将其保存为.html文件。

Any method is welcome! 欢迎任何方法! :) :)

Thanks! 谢谢!

.

Example of what the user could type: Hello my name is Friedpanseller! 用户可以键入的示例:您好我的名字是Friedpanseller!

What the textarea could display: ℋℯ𝓁𝓁ℴ ℳ𝓎 𝒩𝒶𝓂ℯ ℐ𝓈 𝔉𝔯𝔦𝔢𝔡𝔭𝔞𝔫𝔰𝔢𝔩𝔩𝔢𝔯! textarea可以显示的内容:ℋℯ𝓁𝓁ℴℳ𝓎𝒩𝒶𝓂ℯℐ𝓈𝔉𝔯𝔦𝔢𝔡𝔭𝔞𝔫𝔰𝔢𝔩𝔩𝔢𝔯!

Then the user can delete some words in the middle / edit them like a normal textarea 然后用户可以删除中间的一些单词/像普通文本区一样编辑它们

Example of what the user could type: My names are Friedpanseller! 用户可以键入的示例:我的名字是Friedpanseller!

What the textarea could display: ℳ𝓎 𝒩𝒶𝓂ℯ𝓈 𝒜𝓇ℯ 𝔉𝔯𝔦𝔢𝔡𝔭𝔞𝔫𝔰𝔢𝔩𝔩𝔢𝔯! textarea可以显示的内容:ℳ𝓎𝒩𝒶𝓂ℯ𝓈𝒜𝓇ℯ𝔉𝔯𝔦𝔢𝔡𝔭𝔞𝔫𝔰𝔢𝔩𝔩𝔢𝔯!

尝试使用第三方工具(我更喜欢使用CKEditor ),因为它是免费的

Here is an example of what you could do. 是你可以做的一个例子。 Type "a" (without quotes) into that text area. 在该文本区域中键入“a”(不带引号)。 It's not exactly fast , but it's what I could gather. 不是很快 ,但它是我能收集到的。 It doesn't address all of your requests but it's a start. 它没有解决您的所有要求,但它是一个开始。

$("textarea").bind("keyup", function() {
    var cursorPosition = $('textarea').prop("selectionStart");
    var text = $(this).val();
    if (text.indexOf('a') > -1) {
        text = text.replace(/a/g, '𝒶');
        $(this).val(text);
        $('textarea').prop("selectionStart", cursorPosition - 1);
        $('textarea').prop("selectionEnd", cursorPosition - 1);
    }
});

You could try to apply this systematically for the characters you want to substitute. 您可以尝试将此系统地应用于您要替换的角色 Good luck. 祝好运。

When you are adding the code in blank html, please add document.ready for jquery event bind. 当您在空白html中添加代码时,请为jquery事件绑定添加document.ready。

$(document).ready(function(){
$("textarea").bind("keyup", function() {
    var cursorPosition = $('textarea').prop("selectionStart");
    var text = $(this).val();
    if (text.indexOf('a') > -1) {
        text = text.replace(/a/g, '𝒶');
        $(this).val(text);
        $('textarea').prop("selectionStart", cursorPosition - 1);
        $('textarea').prop("selectionEnd", cursorPosition - 1);
    }
});
});

It works this way, if we use the same code in separate HTML page. 如果我们在单独的HTML页面中使用相同的代码,它就会以这种方式工作。

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

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