身份证号尾数计算器 – 在线版

之前曾经写过这个,还有SundayMouse同学写的这个,毕竟人们有需求。但是下载版本的程序毕竟不好用,所以我索性写了个JS版本的,自己可以用网友也可以直接用。


源码:

<script>
function calc(str)
{
/*

          DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
                  Version 2, December 2004

 Copyright (C) 2004 Sam Hocevar <sam@hocevar.net>

 Everyone is permitted to copy and distribute verbatim or modified
 copies of this license document, and changing it is allowed as long
 as the name is changed.

            DO WHAT THE FUCK YOU WANT TO PUBLIC LICENSE
   TERMS AND CONDITIONS FOR COPYING, DISTRIBUTION AND MODIFICATION

  0. You just DO WHAT THE FUCK YOU WANT TO.
*/
	var coeff = [7,9,10,5,8,4,2,1,6,3,7,9,10,5,8,4,2,1];
	var suffix = ['1','0','x','9','8','7','6','5','4','3','2'];
	var sum = 0;
	for(var i=0;i<17;i++)
		sum += coeff[i] * parseInt(str.charCodeAt(i)-48);
	sum %= 11;
	str = str.substr(0,17) + suffix[sum];
	return str;
}
<script>
<button onclick="alert(calc(prompt('请输入待计算的身份证号(前17位)')))" >计算</button>

14 Responses to “身份证号尾数计算器 – 在线版”


发表回复

您的电子邮箱地址不会被公开。 必填项已用 * 标注

Powered by WordPress. Design: Supermodne.