javascripte 实现native2ascii

帮助以前的前端实现了这个native2ascii功能。

<html>

     <head>

       <title>native2ascii</title>

        <script language="javascript">

 function native2ascii(){

     regexp  = /[^\x00-\xff]/g;

     n  =  document.getElementById( 'native' ).value;

     a  =  n;

      while (m  =  regexp.exec(n))  {

         a  =  a.split(m[ 0 ]).join(escape(m[ 0 ]).split( '%' ).join( '\\\\' ));

     }

     document.getElementById( 'ascii' ).value  =  a;

 }

 function ascii2native()  {

      // regexp = /[^\x00-\xff]/g;

     a  =  document.getElementById( 'ascii' ).value;

     n  =  a;

     n  =  unescape(n.split( '\\' ).join( '%' ));
      n = n.replace(/%/g, '');

     document.getElementById('native').value  =  n;

 }

</script> 

</head>

   <body>

          <textarea id ="native" rows ="10" cols ="100"></textarea >

          <p/>

              <input type ="button" id ="convert" value="convert" οnclick="native2ascii()"  />

              <input type ="button" id ="back" value ="back" onclick ="ascii2native()"  />

          <p/>

          <textarea id ="ascii" rows ="10" cols ="100"></textarea >

   </body>

</html>
这只是一个模板,可以修改一下,直接应用到前端代码中。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值