Unicode转换为带有Javascript的表单 [英] Unicode to a Form with Javascript
本文介绍了Unicode转换为带有Javascript的表单的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
为什么当我用javascript的数字字符引用设置unicode时,字符没有转换为正确的表示,但是当我直接从html中设置表单时,它的工作原理是什么?
< html>
< head>
< script language =javascript>
function test()
{
document.InputForm.TextBox.value ='&#1495;';
}
< / script>
< / head>
< body>
< form name =InputFormID =Form1>
< input id =Text1type =textname =TextBoxstyle =color:000000; position:absolute; left:0; top:200; width:600px;value =& amp ;#1495;>
< / input>
< / form>
< form>
< input TYPE =buttonValue =Button1onClick =test();>
< / form>
< form>
< input TYPE =buttonValue =Button2onClick =document.InputForm.TextBox.value ='&#1495;'>
< / form>
< / body>
解决方案
尝试将您的Javascript字符串更改为'\\\ᒕ'
$ b \u是Javascript中的Unicode转义序列
以及代码:
document.InputForm.TextBox.value ='\\\ᒕ';
Why when I set a form with the numeric character reference of an unicode with javascript the character is not converted to its correct representation, but when I set the form directly from the html it works?
<html>
<head>
<script language="javascript">
function test()
{
document.InputForm.TextBox.value = 'ח';
}
</script>
</head>
<body>
<form name="InputForm" ID="Form1">
<input id="Text1" type="text" name="TextBox" style="color: 000000; position: absolute; left: 0; top: 200; width: 600px; " value="ח">
</input>
</form>
<form>
<input TYPE="button" Value="Button1" onClick="test();">
</form>
<form>
<input TYPE="button" Value="Button2" onClick="document.InputForm.TextBox.value = 'ח'">
</form>
</body>
解决方案
Try changing your Javascript string to '\u1495'
\u is the Unicode escape sequence in Javascript
And the code:
document.InputForm.TextBox.value = '\u1495';
这篇关于Unicode转换为带有Javascript的表单的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文