js中的字符替换

时间:2023-03-08 16:58:45
 <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"  "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
 <html>
 <head>
 <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
 <title>Insert title here</title>
 <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/1.6.4/jquery.min.js"></script>
 </head>
 <body>
     <a href='javascript:void(0);' onclick='aa();'>测试</a>
 </body>

 <script>
     function aa(){
     //alert(1);
     //return;
     var  emails='719907411@qq.com';
     //alert(emails); //71****411@qq.com
     //return;
     emails2=emails.replace(/\@/g,"_", emails); //替换71****411@qq.com中的'@'为'_'(下划线)
     //alert(emails2);  //71****411_qq.com
     emails3=emails2.replace(/\./g,"_", emails2); //替换71****411_qq.com中的'.'为'_'(下划线)
     alert(emails3);  //71****411_qq_com
     }
 </script>

 <script>
     function chakan(elm){
         var content=$(elm).parent().prev().find('.kbtn').html();
         if(content==''||content=='选择日期'){
             alert('请选择日期后再查看');
             return false;
         }else{
             content2=content.replace(/\-/g,"", content); //替换2015-02-26中的'-'
             window.location='__URL__/mymoney_packe_list/riqi/'+content2;
         }
     }
 </script>
 </html>