使用特定字符集的HTML文本区域

html textarea using specific character set

本文关键字:HTML 文本 区域 字符集      更新时间:2023-09-26

我想"强制"一个特定的字符集(ISO-8859-1)在一个页面的特定文本区域的html标签。

我不确定这在HTML或使用JS技术中是否可行,但要给出我想要实现的想法:

<textarea character-set="ISO-8859-1"></textarea>

以上应该允许用户输入仅属于ISO-8859-1字符集的字符,像€(EUR)这样的字符应该被阻止/显示为虚拟字符。

我问这个问题是因为我的网站集成了一个只支持ISO-8859-1字符的第三方服务,我希望用户输入消息时立即看到一些字符是不允许的。

希望这是有意义的,谢谢你

如果您希望只接受表单中给定的字符集,这个链接到W3Schools表单与"accept-charset=yourTargetCharSet"显示了如何强制表单只接受某些字符集。(http://www.w3schools.com/tags/att_form_accept_charset.asp)

或者,您可以捕获并转换任何输入的文本为需要使用以下ISO转换参考(http://www.w3schools.com/charsets/ref_html_8859.asp)

//In this scenario you would want to ID your textarea and gather the
//inputted values something like the following
<textarea id="getMeName"></textarea>
<textarea id="getMeOther"></textarea>
<script>
var thisFormNameData = document.getElementById("getMyName") 
//or the other id, and then you could manipulate that variable as
//needed to better suit your ISO within a UTF-8 doc
</script>