« Unicode 脫逸序列轉換 | 網頁 | 準備展開 .NET 之旅 »
13/11/2004
Unicode 脫逸序列轉換
這裡提供一段程式碼,可以透過 JavaScript 將文字轉換為 Unicode 脫逸序列。這段程式碼,不論是對網頁開發人員,還是對 java resource bundle 的翻譯人員,都有很大的方便性。使用時只要將底下的程式碼複製起來,以 html 副檔名儲存,就可以用 browser 執行了。
<META HTTP-EQUIV="Content-Type" CONTENT="text/html; charset=big5"><script language=javascript>
<!--
function StringToUniCode(source) {
sret = "";
// Unicode 跳脫序列之格式為 u00ff
for(var i=0; i < source.length; i++) {
var num = new Number( source.charCodeAt(i));
sret += "\u" + num.toString(16);
}
return sret;
}
function convert(){
document.forms.content.result.value
= StringToUniCode(document.forms.content.source.value);
}
//-->
</script>
將文字轉成 Unicode 跳脫序列
<form name=content>
來源:<input type=TEXT name=source size=40 value="常用連絡人"><br>
結果:<input type=TEXT name=result size=40><br>
<input type=button value=轉換 onclick="convert()">
06:50 發表於 Developing, Web | 永久網址 | 留言 (1) | Email this | Tags: Programming, javascript, unicode, convert
留言
你好,我看到了你的"Unicode 脫逸序列轉換"
這是個不錯的程式碼
不過我想請問一下如何在網頁上輸入此一序列轉換後再次得到此中文字而不需靠unicode的輸入法?
感謝回答
發表人: 大頭 | 27/06/2005


