我想为页面中的特定 textarea html 标记“强制”使用特定字符集 (ISO-8859-1)。
我不确定这在 HTML 中或使用 JS 技术是否可行,但我想了解一下我想要实现的目标:
<textarea character-set="ISO-8859-1"></textarea>
上面的内容应该允许用户输入仅属于 ISO-8859-1 字符集一部分的字符,像 € (EUR) 这样的字符应该被阻止/显示为虚拟字符。
我问这个问题是因为我的网站与仅支持 ISO-8859-1 字符的第三方服务集成,并且我希望输入消息的用户立即看到某些字符是不允许的。
希望这是有意义的,谢谢
最佳答案
如果您希望仅接受表单中的给定字符集,此带有“accept-charset=yourTargetCharSet”的 W3Schools 表单的链接显示了如何强制表单仅接受某些字符集。 (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>
关于javascript - 使用特定字符集的 html 文本区域,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32357946/