我有个案子:
有一个数字字段,必须填入10个编号的用户ID。我需要自动检查该ID是否存在。公式为:(p1 * 2) + (p2 * 4) + (p3 * 8) + (p4 * 5) + (p5) * 10) + (p6) * 9) + (p7 * 7) + (p8) * 3) + (p9 * 6) % 11 = p10,其中p1是第一位数,p2是第二位数,依此类推。
我是javascript新手,非常感谢你的帮助。下面是我尝试过的:
if ((((this.position(1) * 2) + (this.position(2) * 4) + (this.position(3) * 8) + (this.position(4) * 5) + (this.position(5) * 10) + (this.position(6) * 9) + (this.position(7) * 7) + (this.position(8) * 3) + (this.position(9) * 6)) % 11) == this.position(10))
{
}
else
{
xfa.host.messageBox("Wrong ID", "ERROR!", 1, 0);
}发布于 2014-01-10 01:21:08
像这样的东西将会起作用:
var s = this.rawValue;
var prod = s.substr(0,1)*2 + s.substr(1,1)*4 + s.substr(2,1)*8 +...
if (prod%11 == s.substr(9,1)){
//do whatever
}
else {
//do whatever else
}请记住substr()函数从0开始,而不是从1开始,第二个1确保只接受一个字符。
https://stackoverflow.com/questions/18099679
复制相似问题