我有检查国家代码的通用算法。每个代码都有10位数字:
function Nationalcode(code)
{
var L=code.length;
if(L<8 || parseInt(code,10)==0) return false;
code=('0000'+code).substr(L+4-10);
if(parseInt(code.substr(3,6),10)==0) return false;
var c=parseInt(code.substr(9,1),10);
var s=0;
for(var i=0;i<9;i++)
s+=parseInt(code.substr(i,1),10)*(10-i);
s=s%11;
return (s<2 && c==s) || (s>=2 && c==(11-s));
return true;
}
当我添加方法并使用@ click =“ check”运行该方法时,效果很好:
check: function(){
var c=document.getElementById("CodeM").value;
if( checkCodeMeli(c))
alert("true");
else
alert("fasle");
}
但是我想在用户输入10位数字时自动检查:
<input type="text" v-model="nationalcode" id="CodeM" v-on:keyup.enter="queryForKeywords" v-on:keydown="queryForKeywords">
queryForKeywords: function() {
this.$nextTick(() => {
var c=document.getElementById("CodeM").value;
this.isActive = 'false';
if (this.nationalcode.length == 9 ) {
if( checkCodeMeli(c)){
alert("true");
}
else{
alert("false");
}
}
else{
}
});
},
0011433876, 按钮:是的, auto:true,
0011433875: 按钮:假, auto:true,
0011433874: 按钮:假, auto:true,
所有按钮的答案均为“正确”,但只有第一个正确。