javascript - 使用特定字符集的 html 文本区域

标签 javascript html character-encoding iso-8859-1

我想为页面中的特定 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/

相关文章:

android-studio - 用于编码CP1252的字符-Android Studio吗?

javascript - 当我将 SVG 内容绘制到 Canvas 时,SVG 被裁剪

javascript - 想要使用 javascript 将一组大片与 esri 合并

Javascript 不对加载的元素进行操作

jquery - 火狐漏洞 : Footer wrapping around main content

php - 如何使用 PHP 替换阿拉伯字母的初始形式?

Javascript 将数据插入 HTML 表格

javascript - 使用 knockout 在一页中进行多个自动刷新数据绑定(bind)

html - 基于元标记在页面上的位置对 SEO 的影响

php - 在 PHP 中检测正确的字符编码?