相关文章推荐
有腹肌的卡布奇诺  ·  js ...·  3 周前    · 
旅途中的小熊猫  ·  JavaScript 之 ...·  3 周前    · 
淡定的墨镜  ·  Flutter之GlobalKey详解_fl ...·  1 年前    · 
干练的面包  ·  Android ...·  2 年前    · 
成熟的单杠  ·  Flutter ...·  2 年前    · 
!function () { document.getElementById('bankCard').onkeyup = function (event) { var v = this.value; if(/\S{5}/.test(v)){ this.value = v.replace(/\s/g, '').replace(/(.{4})/g, $1 ); 2、jQuery写法 </t // 将 <em> 字符串 </em> 的每 <em> 个字符 </em> 都添 <em> 加 </em> 一个0:a --> a0 然后删除最后一个 0 function insert(str) { for (let i = 0; i < str.length; i += 2) { str = str.replace(str[i], str[i] + '. var v = obj.value; console.info(v); v =v.replace(/(\s)/g,'').replace(/(\d{4})/g,'$1 ').replace(/\s*$/,'') obj.value =v; }原理:首先将现有的输 var num1 = '82452365122547854' var num2 = num1.replace(/(.{4})/g, "$1 ") console.log('正常显示:',num1) console.log('每四位数用 <em> 空格 </em> 隔开:',num2) 控制台输出为: var getIc = function (ic){ var arric = ic.split(“,”); randomIc = arric[Math.floor(Math.random()*(arric.length))]; return randomIc return function (oc,ic,re){ var reStr = “(.{“+re+”}|.*)”; var reg = new RegExp(reStr,”g”); var ocArray = oc.match(reg) var arrLength = <div class="desc ellipsis-online ellipsis-online-1"> 转自:http://www.haorooms.com/post/ <em> js </em> _yinghangkahao 今天来讲讲 <em> js </em> 中实现input中输入数字,控制每四位 <em> 加 </em> 一个 <em> 空格 </em> 的方法!这个主要是应用于我们在填写表单的时候,填写银行卡信息,要求我们输入的数字是四位一个 <em> 空格 </em> !今天主要介绍两种方式来实现这个方法!但是都运用到了键盘码。下面我就列举一下键盘码,以备后面查阅! 键盘各按键对应的数字 key... </div> <div class="desc ellipsis-online ellipsis-online-1"> var str = '2016060520103600466'; var str=str.replace(/\s/g,'').replace(/(.{4})/g,"$1 "); alert(str); 转载于:https://www.cnblogs.com/xiaozhumaopao/p/7651054.html </div> var str = "abcdefg"; str = str.replace(/(.{2})/g, "$1,"); console.log(str); // "ab,cd,ef,g" 解释一下: - `/(.{2})/g`:正则表达式,表示匹配任意两 <em> 个字符 </em> 组成的 <em> 字符串 </em> ,`g`表示全局匹配。 - `"$1,"`:替换 <em> 字符串 </em> ,表示将匹配到的 <em> 字符串 </em> 后面 <em> 加 </em> 上逗号。 - `str.replace`: <em> 字符串 </em> 的replace方法,将匹配到的 <em> 字符串 </em> 替换成指定的 <em> 字符串 </em> 。 这样就可以实现 <em> 每隔 </em> 两 <em> 个字符 </em> <em> 加 </em> 一个逗号的效果了。 <div class="sep10"></div> </div> </div> </div> <div class="topic_buttons"> <div class="fr gray f11" style="line-height: 12px; padding-top: 3px; text-shadow: 0px 1px 0px #fff;">   </div> </div> </div> <div class="sep5"></div> <div class="box"> <div class="cell"> <span class="gray">推荐文章</span> </div> <div class="cell"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="32" valign="top" align="center"> <a href="http://code.python88.com/u/S2hKXqnOce" ><img src="http://img.python88.com/avatars/avatars/user-default.jpg?imageView2/2/w/100&imageView2/2/w/100" class="avatar" style="max-width: 32px; max-height: 32px;" border="0" align="default"></a> </td> <td width="10" valign="top"></td> <td width="auto" valign="top" align="left"> <span class="item_hot_topic_title"> <a href="http://code.python88.com/u/S2hKXqnOce">想发财的野马</a>  ·  <a target="_blank" href="http://code.python88.com/l/5lDPKp3pSa">JavaScript实现解析xml文件数据_js解析xml</a> </span> <div class="sep5"></div> <span class="fade">1 月前</span> <small class="gray"> </small> </td> </tr> </tbody> </table> </div> <div class="cell"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="32" valign="top" align="center"> <a href="http://code.python88.com/u/Nwo4CutCTI" ><img src="http://img.python88.com/avatars/avatars/user-default.jpg?imageView2/2/w/100&imageView2/2/w/100" class="avatar" style="max-width: 32px; max-height: 32px;" border="0" align="default"></a> </td> <td width="10" valign="top"></td> <td width="auto" valign="top" align="left"> <span class="item_hot_topic_title"> <a href="http://code.python88.com/u/Nwo4CutCTI">有腹肌的卡布奇诺</a>  ·  <a target="_blank" href="http://code.python88.com/l/lLpNTifHPa">js jquery-ajax/fetch请求时数据文本丢失加号和连接号的问题 - 深入学习ing </a> </span> <div class="sep5"></div> <span class="fade">3 周前</span> <small class="gray"> </small> </td> </tr> </tbody> </table> </div> <div class="cell"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="32" valign="top" align="center"> <a href="http://code.python88.com/u/R6l0KuvezK" ><img src="http://img.python88.com/avatars/avatars/user-default.jpg?imageView2/2/w/100&imageView2/2/w/100" class="avatar" style="max-width: 32px; max-height: 32px;" border="0" align="default"></a> </td> <td width="10" valign="top"></td> <td width="auto" valign="top" align="left"> <span class="item_hot_topic_title"> <a href="http://code.python88.com/u/R6l0KuvezK">旅途中的小熊猫</a>  ·  <a target="_blank" href="http://code.python88.com/l/LZTOBg17BJ">JavaScript 之 使用方式、函数定义与调用、(局部、全局)变量 - 鹿先森JIAN </a> </span> <div class="sep5"></div> <span class="fade">3 周前</span> <small class="gray"> </small> </td> </tr> </tbody> </table> </div> <div class="cell"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="32" valign="top" align="center"> <a href="http://code.python88.com/u/b53eJ8dSp4" ><img src="http://img.python88.com/avatars/avatars/user-default.jpg?imageView2/2/w/100&imageView2/2/w/100" class="avatar" style="max-width: 32px; max-height: 32px;" border="0" align="default"></a> </td> <td width="10" valign="top"></td> <td width="auto" valign="top" align="left"> <span class="item_hot_topic_title"> <a href="http://code.python88.com/u/b53eJ8dSp4">淡定的墨镜</a>  ·  <a target="_blank" href="http://code.python88.com/l/tcD5brDhSz">Flutter之GlobalKey详解_flutter globalkey-CSDN博客</a> </span> <div class="sep5"></div> <span class="fade">1 年前</span> <small class="gray"> </small> </td> </tr> </tbody> </table> </div> <div class="cell"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="32" valign="top" align="center"> <a href="http://code.python88.com/u/ZuQCCO6cBj" ><img src="http://img.python88.com/avatars/avatars/user-default.jpg?imageView2/2/w/100&imageView2/2/w/100" class="avatar" style="max-width: 32px; max-height: 32px;" border="0" align="default"></a> </td> <td width="10" valign="top"></td> <td width="auto" valign="top" align="left"> <span class="item_hot_topic_title"> <a href="http://code.python88.com/u/ZuQCCO6cBj">小胡子的大葱</a>  ·  <a target="_blank" href="http://code.python88.com/l/RjVfLGfz08">远程JMX访问拒绝:Caused by: java.rmi.ConnectException: Connection refused to host: 127.0.0.1; nested - 天宇轩-</a> </span> <div class="sep5"></div> <span class="fade">1 年前</span> <small class="gray"> </small> </td> </tr> </tbody> </table> </div> <div class="cell"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="32" valign="top" align="center"> <a href="http://code.python88.com/u/RB9aqOugRp" ><img src="http://img.python88.com/avatars/avatars/user-default.jpg?imageView2/2/w/100&imageView2/2/w/100" class="avatar" style="max-width: 32px; max-height: 32px;" border="0" align="default"></a> </td> <td width="10" valign="top"></td> <td width="auto" valign="top" align="left"> <span class="item_hot_topic_title"> <a href="http://code.python88.com/u/RB9aqOugRp">干练的面包</a>  ·  <a target="_blank" href="http://code.python88.com/l/RTupXC32k2">Android 中东阿拉伯语适配,看这一篇够了 - 掘金</a> </span> <div class="sep5"></div> <span class="fade">2 年前</span> <small class="gray"> </small> </td> </tr> </tbody> </table> </div> <div class="cell"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="32" valign="top" align="center"> <a href="http://code.python88.com/u/DA6DlDt5Il" ><img src="http://img.python88.com/avatars/avatars/user-default.jpg?imageView2/2/w/100&imageView2/2/w/100" class="avatar" style="max-width: 32px; max-height: 32px;" border="0" align="default"></a> </td> <td width="10" valign="top"></td> <td width="auto" valign="top" align="left"> <span class="item_hot_topic_title"> <a href="http://code.python88.com/u/DA6DlDt5Il">憨厚的西红柿</a>  ·  <a target="_blank" href="http://code.python88.com/l/YBHF0N1wqT">【Log日志】打印mybatis中sql日志并存放到指定文件中 - 知乎</a> </span> <div class="sep5"></div> <span class="fade">2 年前</span> <small class="gray"> </small> </td> </tr> </tbody> </table> </div> <div class="cell"> <table cellpadding="0" cellspacing="0" border="0" width="100%"> <tbody> <tr> <td width="32" valign="top" align="center"> <a href="http://code.python88.com/u/8bSH4Sc1qs" ><img src="http://img.python88.com/avatars/avatars/user-default.jpg?imageView2/2/w/100&imageView2/2/w/100" class="avatar" style="max-width: 32px; max-height: 32px;" border="0" align="default"></a> </td> <td width="10" valign="top"></td> <td width="auto" valign="top" align="left"> <span class="item_hot_topic_title"> <a href="http://code.python88.com/u/8bSH4Sc1qs">成熟的单杠</a>  ·  <a target="_blank" href="http://code.python88.com/l/2uiHyTNAm3">Flutter Text文字下方出现黄色双下划线 - 掘金</a> </span> <div class="sep5"></div> <span class="fade">2 年前</span> <small class="gray"> </small> </td> </tr> </tbody> </table> </div> </div> <div class="sep5"></div> <div class="box"> <div class="cell"> <script async src="//pagead2.googlesyndication.com/pagead/js/adsbygoogle.js"></script> <!-- 普通广告(正在使用) --> <ins class="adsbygoogle" style="display:block" data-ad-client="ca-pub-1837452791782084" data-ad-slot="6787195013" data-ad-format="auto" data-full-width-responsive="true"></ins> <script> (adsbygoogle = window.adsbygoogle || []).push({}); </script> </div> </div> <div class="sep5"></div> </div> </div> <div class="c"></div> <div class="sep20"></div> </div> <div id="Bottom"> <div class="content footer"> <div class="inner"> <div class="sep10"></div> <div class="fr"> </div> <strong> <a href="http://www.jintiankansha.me/" class="dark" target="_blank">今天看啥</a>   <span class="snow">·</span>   <a href="http://www.python88.com/" class="dark" target="_blank">Py中国</a>   <span class="snow">·</span>   <a href="http://www.codingpro.cn/" class="dark" target="_blank">codingpro</a>   <span class="snow">·</span>   <a href="http://baike.linkmax.top" class="dark" target="_blank">小百科</a>   <span class="snow">·</span>   <a href="http://www.linkmax.top" class="dark" target="_blank">link之家</a>   <span class="snow">·</span>   <a href="http://www.wolongai.cn" class="dark" target="_blank">卧龙AI搜索</a> </strong> <div class="sep10"></div> 删除内容请联系邮箱 2879853325@qq.com <div class="sep10"></div> Code - 代码工具平台 <div class="sep10"></div> <span class="f12 gray">© 2024 ~ <a href="http://beian.miit.gov.cn/" target="_blank" rel="nofollow">沪ICP备11025650号</a></span> <div class="sep10"></div> </div> </div> </div> <script type="text/javascript" src="https://img.100weidu.com/cdn/highlight.js/9.2.0/highlight.min.js"></script> <script type="text/javascript" src="https://img.100weidu.com/cdn/jquery/1.11.0/jquery.min.js"></script> <script type="text/javascript" src="https://img.100weidu.com/cdn/jqueryui/1.9.2/jquery-ui.min.js"></script> <script type="text/javascript" src="/static/js/site/base/common.js?v=97646d06e4a04b2bf43b7b467cfd321e"></script> <script type="text/javascript" src="/static/js/site/base/v2ex.js?v=d41d8cd98f00b204e9800998ecf8427e"></script> <script type="text/javascript" src="/static/js/site/base/base.js?v=4734e41dc8139093c113d6a48489a0f4"></script> <script> var _hmt = _hmt || []; (function () { var hm = document.createElement("script"); hm.src = "https://hm.baidu.com/hm.js?94b9935d8881b2e37490d19acfb0f6e4"; var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(hm, s); })(); </script> <!-- Google tag (gtag.js) --> <script async src="https://www.googletagmanager.com/gtag/js?id=G-P95KGR6D7D"></script> <script> window.dataLayer = window.dataLayer || []; function gtag(){dataLayer.push(arguments);} gtag('js', new Date()); gtag('config', 'G-P95KGR6D7D'); </script> <script> (function () { var bp = document.createElement('script'); var curProtocol = window.location.protocol.split(':')[0]; if (curProtocol === 'https') { bp.src = 'https://zz.bdstatic.com/linksubmit/push.js'; } else { bp.src = 'http://push.zhanzhang.baidu.com/push.js'; } var s = document.getElementsByTagName("script")[0]; s.parentNode.insertBefore(bp, s); })(); </script> <!-- 多条广告如下脚本只需引入一次 --> <script type="text/javascript" src="//cpro.baidustatic.com/cpro/ui/cm.js" async="async" defer="defer"> </script> <script type="text/javascript" src="/static/js/site/post/post_common.js?v=8d0f2fe55813416f744bc961e1768685"></script> </body> </html>