console
function isbn10(code) {
code = (code + '').replace(/[-\s]/g, '');
if (!/^\d{9}[\dxX]?$/.test(code)) return false;
var i = 0, c = 0; // c:checksum
for (; i < 9;)
c += code.charAt(i++) * i;
c %= 11; if (c == 10) c = 'X';
if (code.length == 9) return code + c;
return c == (i = code.charAt(9)) || c == 'X' && i == 'x';
}
function isbn13(code){
code = (code + "").replace(/[-\s]/g, "")
if (!/^\d{12,13}$/.test(code)) return false
var i = 1,
c = 0 // c:checksum
for (; i < 12; i += 2) c += Math.floor(code.charAt(i))
for (c *= 3, i = 0; i < 12; i += 2) c += Math.floor(code.charAt(i))
c = (220 - c) % 10 // 220:大于(1*6+3*6),%10==0即可。
if (code.length == 12) return code + c
return c == code.charAt(12)
}
function submit() {
var oInput = document.getElementById("app")
console.log("结果", oInput)
var r = isbn13(oInput.value)
console.log("结果", r)
var r1 = isbn10(oInput.value)
console.log("结果", r1)
}
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<title>菜鸟教程(runoob.com)</title>
</head>
<body>
ISBN: <input type="text" name="FirstName" id="app" ><br>
<input type="submit" value="提交" onclick="submit()">
</body>
</html>