我想为页面中的特定文本区域html标记“强制”一个特定字符集(ISO-8859-1)。
我不确定这在HTML中或使用JS技术是否可行,但给出我想要实现的想法:
<textarea character-set="ISO-8859-1"></textarea>上面应该允许用户输入的字符只是ISO-8859-1字符集的一部分,像EUR (EUR)这样的字符应该被阻止/显示为虚拟字符。
我问这个是因为我的网站集成了第三方服务,只支持ISO-8859-1字符,我希望输入消息的用户立即看到一些字符是不允许的。
希望这是有意义的,谢谢
发布于 2015-09-03 00:10:39
如果您希望只接受表单中的给定字符集,这个带有" 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>https://stackoverflow.com/questions/32357946
复制相似问题