<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Document</title>
<style>
#msg{
color: red;
}
</style>
</head>
<body>
身份证号:<input id="id-card" type="text">(前17位)<br>
(校验位)最后一位为:<span id="msg"></span><span id="check-digit"></span><br>
<button onclick="calculate()">计算</button><br>
<script>
"use strict";
// 前17位每项的系数
let coefficient = [7, 9, 10, 5, 8, 4, 2, 1, 6, 3, 7, 9, 10, 5, 8, 4, 2];
// 除11取余的结果对应的校验位(最后一位)的值
let checkDigitMap = ['1', '0', 'X', '9', '8', '7', '6', '5', '4', '3', '2'];
function calculate(){
var idCa
ISO 7064:1983.MOD11-2校验码计算法(身份证18位效验码计算)
于 2022-03-01 17:20:49 首次发布