JSFiddle - React, Tailwind, and code Playground

by Fed json

HTML

<label for="A">身份证号:</label>
<input id="A" type="text" onblur="ExtractionBirthday('A','B')" >
<label for="B">出生日期:</label>
<input type="text" id="B">

JavaScript

function	ExtractionBirthday(firstText,secondText){
	var textTerm = document.getElementById("firstText").value;
  
  if(textTerm.length == "18"){
  	var byear =  textTerm.substring(6,10);
    var bmonth = textTerm.substring(10,12);
    var bday =  textTerm.substring(12,14);
    document.getElementById("secondText").value = byear+''+bmonth+''+bday;
  
  }else{
  	alert("输入的身份证不正确!");
  document.getElementById(firstText).focus();
  document.getElementById(firstText).value="";
  }

}