本工具的作用呢?就是把页面里JS用到的汉字转义成字符串,这些字符串可以替换了js字符串变量里的汉字信息。
支持字符串与汉字之间互转。
支持IE,FF等浏览器的点击复制功能。话不多说,代码分享如下。。。
——————————————————————————————————————————
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>汉字编码简易转换工具--Byhonlee</title>
<style type="text/css">
*{
font-family:Arial, Helvetica, sans-serif;
font-size:12px;
}
.k{ width: 350px; height: auto; float: left;
}
.cls{ clear: both;}
</style>
<script type="text/javascript">
window.onload=function(){
document.getElementById("txt").value="/u8FD9/u91CC/u662F/u8981/u8F6C/u6362/u7684/u6C49/u5B57";
document.getElementById("val").value="/u8FD9/u91CC/u662F/u8981/u8F6C/u6362/u7684/u8F6C/u4E49/u5B57/u7B26/u4E32";
}
var zhuan=function(){
document.getElementById("val").value=escape(document.getElementById("txt").value).replace(//%/g,'//');
}
var rzhuan=function(){
document.getElementById("txt").value=unescape((document.getElementById("val").value).replace(////g,'%'));
}
var cls=function(str){
if(str=='l'){
document.getElementById("txt").value="";
}else if(str='r'){
document.getElementById("val").value="";
}else{
document.getElementById("txt").value="";
document.getElementById("val").value="";
}
}
var lcopy=function(){
copyToClipboard(document.getElementById("txt").value);
}
var rcopy=function(){
copyToClipboard(document.getElementById("val").value);
}
var copyToClipboard=function(selContent) {
if(selContent==''){alert('/u5185/u5BB9/u4E3A/u7A7A/uFF01');return false;}
if(window.clipboardData) {
window.clipboardData.clearData();
window.clipboardData.setData("Text", selContent);
alert("IE/u4E0B/u590D/u5236/u6210/u529F/uFF01");
} else if(navigator.userAgent.indexOf("Opera") != -1) {
window.location = selContent;
} else if (window.netscape) {
try {
netscape.security.PrivilegeManager.enablePrivilege("UniversalXPConnect");
} catch (e) {
alert("/u88AB/u6D4F/u89C8/u5668/u62D2/u7EDD/uFF01/5Cn/u8BF7/u5728/u6D4F/u89C8/u5668/u5730/u5740/u680F/u8F93/u5165/27about/3Aconfig/27/u5E76/u56DE/u8F66/5Cn/u7136/u540E/u5C06/27signed.applets.codebase_principal_support/27/u8BBE/u7F6E/u4E3A/27true/27");
}
var clip = Components.classes['@mozilla.org/widget/clipboard;1'].createInstance(Components.interfaces.nsIClipboard);
if (!clip)
return;
var trans = Components.classes['@mozilla.org/widget/transferable;1'].createInstance(Components.interfaces.nsITransferable);
if (!trans)
return;
trans.addDataFlavor('text/unicode');
var str = new Object();
var len = new Object();
var str = Components.classes["@mozilla.org/supports-string;1"].createInstance(Components.interfaces.nsISupportsString);
var copytext = selContent;
str.data = copytext;
trans.setTransferData("text/unicode",str,copytext.length*2);
var clipid = Components.interfaces.nsIClipboard;
if (!clip)
return false;
clip.setData(trans,null,clipid.kGlobalClipboard);
alert("FF/u4E0B/u590D/u5236/u6210/u529F/uFF01");
}
}
</script>
</head>
<body>
<div class="k"><textarea name="txt" id="txt" cols="40" rows="6" onfocus="cls('l');" title="点击清除内容"></textarea>
<input type="button" name="but" value="汉字转换To字符" onclick="zhuan();">
<input type="button" name="cls" value="复制汉字" onclick="lcopy();"></div>
<div class="k"><textarea name="val" id="val" cols="40" rows="6" onfocus="cls('r');" title="点击清除内容"></textarea>
<input type="button" name="but" value="字符转换To汉字" onclick="rzhuan();">
<input type="button" name="cls" value="复制字符" onclick="rcopy();"></div>
<div class="cls"></div><Br /><hr /><Br /><input type="button" name="cls" value="清空全部" onclick="cls();">
</body>
</html>
————————————————————————————————————————————————————————
此文中代码非最新版,如果想用最新版的话,请点此下载。。。http://download.youkuaiyun.com/source/3372409
这是一个用于汉字与字符串之间快速转换的工具,支持IE和Firefox等浏览器的点击复制功能。用户可以输入汉字,工具会将其转换为相应的字符串,反之亦然。


被折叠的 条评论
为什么被折叠?



