1. 程式人生 > >JS input 銀行卡號格式轉換

JS input 銀行卡號格式轉換

news tel lang doctype onkeydown htm files head nbsp

傳送門:http://demo.sc.chinaz.com//Files/DownLoad/webjs1/201411/jiaoben2920/

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <title>js銀行卡號格式輸入框 - 站長素材</title>
    <style>
    *{margin:0;padding:0;}
    input{margin:100px auto;display:block;border:1px solid #
000;width:200px;height:30px;line-height:30px;} </style> <script> window.onload=function() { var oT=document.getElementById(‘text‘); oT.onkeydown=function(ev) { var oW=oT.value; var oEvent=ev||event; if(oEvent.keyCode==8) {
if(oW) { for(var i=0;i<oW.length;i++) { var newStr=oW.replace(/\s$/g,‘‘); } oT.value=newStr } }else{ for(var i=0;i<oW.length;i++) {
var arr=oW.split(‘‘); if((i+1)%5==0) { arr.splice(i,0,‘ ‘); } } oT.value=arr.join(‘‘); } } } </script> </head> <body> <input id="text" type="text" value=""> <div style="text-align:center;margin:50px 0; font:normal 14px/24px ‘MicroSoft YaHei‘;"> <p>適用瀏覽器:IE8、360、FireFox、Chrome、Safari、Opera、傲遊、搜狗、世界之窗. </p> <p>來源:<a href="http://sc.chinaz.com/" target="_blank">站長素材</a></p> </div> </body> </html>

JS input 銀行卡號格式轉換