
易语言 怎么把这段js写成代码
<body><p><textareaname="source"rows="14"id="source"style="width:99%">在此处输入未解码文本,例:\u8...
<body>
<p>
<textarea name="source" rows="14" id="source" style="width:99%">在此处输入未解码文本,例:\u8BF7\u9009\u62E9</textarea>
</p>
<div class="btn">
<a href="javascript:action('RECONVERT')">ReConvert To 汉字</a>
</div>
<p>
<div id="tt" style="display:none"></div>
<textarea name="show2" rows="14" id="show2" style="width:99%"></textarea>
</p>
</body>
<script language="javascript" type="text/javascript">
var oSource = document.getElementById("source");
var oShow2 = document.getElementById("show2");
var oTt = document.getElementById("tt");
function action(pChoice){
switch(pChoice){
case "CONVERT_FMT1":
oShow2.value = ascii(oSource.value);
break;
case "CONVERT_FMT2":
oShow2.value = unicode(oSource.value);
break;
case "RECONVERT":
oShow2.value = reconvert(oSource.value);
break;
}
}
function ascii(str){
return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\$2;")});
}
function unicode(str){
return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")});
}
function reconvert(str){
str = str.replace(/(\\u)(\w{4})/gi,function($0){
return (String.fromCharCode(parseInt((escape($0).replace(/(%5Cu)(\w{4})/g,"$2")),16)));
});
str = str.replace(/()(\w{4});/gi,function($0){
return String.fromCharCode(parseInt(escape($0).replace(/(%26%23x)(\w{4})(%3B)/g,"$2"),16));
});
return str;
}
</script> 展开
<p>
<textarea name="source" rows="14" id="source" style="width:99%">在此处输入未解码文本,例:\u8BF7\u9009\u62E9</textarea>
</p>
<div class="btn">
<a href="javascript:action('RECONVERT')">ReConvert To 汉字</a>
</div>
<p>
<div id="tt" style="display:none"></div>
<textarea name="show2" rows="14" id="show2" style="width:99%"></textarea>
</p>
</body>
<script language="javascript" type="text/javascript">
var oSource = document.getElementById("source");
var oShow2 = document.getElementById("show2");
var oTt = document.getElementById("tt");
function action(pChoice){
switch(pChoice){
case "CONVERT_FMT1":
oShow2.value = ascii(oSource.value);
break;
case "CONVERT_FMT2":
oShow2.value = unicode(oSource.value);
break;
case "RECONVERT":
oShow2.value = reconvert(oSource.value);
break;
}
}
function ascii(str){
return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\$2;")});
}
function unicode(str){
return str.replace(/[^\u0000-\u00FF]/g,function($0){return escape($0).replace(/(%u)(\w{4})/gi,"\\u$2")});
}
function reconvert(str){
str = str.replace(/(\\u)(\w{4})/gi,function($0){
return (String.fromCharCode(parseInt((escape($0).replace(/(%5Cu)(\w{4})/g,"$2")),16)));
});
str = str.replace(/()(\w{4});/gi,function($0){
return String.fromCharCode(parseInt(escape($0).replace(/(%26%23x)(\w{4})(%3B)/g,"$2"),16));
});
return str;
}
</script> 展开
2个回答
展开全部
最简单的办法就是把这些代码分别用常量保存,然后调用的时候就自己组合常量。
更多追问追答
追问
就是要这样。。。。
追答
既然你都知道这样做,那你还问。。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询