Home > front end >  With js extract id number in the year
With js extract id number in the year

Time:04-19

substr () method can extract in the string specified number of characters from the start subscript,

StringObject. Substr (start, length)

1 kind of use the substr () directly extract

<script>

Var card=(prompt (" please enter the id number));

YearB=card. Substr (6, 4);

The console. The log (yearB);

YearB=2021 - yearB;



The switch (yearB> 18)={
Case true:

Alert (' your id number is: + card + '\ n' + "this year you + yearB + years old, adult, boot success!!!!! ");

break;

Case false:

Alert (' your id number is: + card + '\ n' + "this year you + yearB + years old, is a minor, suggest to find id card!!!!! ");

break;

}

</script>

The second use division



<meta charset="utf-8" & gt;

<meta HTTP - equiv="X - UA - Compatible" content="IE=edge" & gt;

<meta name="viewport" content="width=device - width, initial - scale=1.0" & gt;

Internet cafes boot & lt;/title> <br/><br/><script> <br/><br/>Var card=(prompt (" please enter the id number)); <br/><br/>Var year=card/* * 8 (10); <br/><br/>Var yearA=year % (10 * * 4); <br/><br/>YearB=parseInt (2021 - yearA); <br/><br/><br/><br/>The console. The log (card); <br/><br/>The console. The log (year); <br/><br/>The console. The log (yearA); <br/><br/>The console. The log (yearB); <br/><br/><br/><br/>The switch (yearB> 18)={<br/>Case true: <br/><br/>Alert (' your id number is: + card + '\ n' + "this year you + yearB + years old, adult, boot success!!!!! "); <br/><br/>break; <br/><br/>Case false: <br/><br/>Alert (' your id number is: + card + '\ n' + "this year you + yearB + years old, is a minor, suggest to find id card!!!!! "); <br/><br/>break; <br/><br/>} <br/><br/></script> </div> <div class="th_page th_page_color"></div> <div class="umCopyright"> <p>Page link:<a href="/frontend/108521.html" target="_blank" style="color:#999">https//www.codepudding.com/frontend/108521.html</a></p> </div> <div class="detail-arr"> <div class="detail-arr-left">Prev:<a href='/frontend/108520.html'>Could not load existing sourcemap of "../Shared/TFJS - examp les. CSS ".</a></div> <div class="detail-arr-right">Next:<a href='/frontend/108522.html'>Asp to generate static local normal, database stuck to the server is running</a></div> </div> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="hot-tags neitags"> <ul> <li><i class="iconfont icon-x-tags"></i> Tags:  </li> <a href='/e/tags/?tagname=JavaScript' target='_blank'>JavaScript</a> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="xiangguan"> <ul class="msg msghead"> <li class="tbname">Related</li> </ul> <ul> </ul> </div> </div> </div> </div> <div class="container th_top"> <div class="row"> <div class="col-md-12"> <div class="flinks"> <ul> <li><i class="iconfont icon-x-tags"></i> Links:  </li> <li class="liflinks"><a target="_blank" href="/" title="CodePudding">CodePudding</a></li> </ul> </div> </div> </div> </div> <div class="footer"> <p><span style="font-size:16px;color:#666;font-weight: bold">About Us:</span>  <a href="https://www.codepudding.com/contact.html">Contact Us</a>      <a href="https://www.codepudding.com/service.html">Terms of Service</a>      <a href="https://www.codepudding.com/privacy.html"> Privacy Policy</a></p> <p class="foot_info">Copyright © 2010-2023,Powered By <a href="/" target="_blank">CodePudding</a> </p> </div> <script type="text/javascript" src="/skin/code/tianhu.js"></script> </body></html>