说明

在系统中须要检查税率填写的正确性,一定是国家规定的某几种税率,当然能够通过if else进行校验,可是还能够使用定义一个数组然后校验是否包括在元素中进行校验。

长处:加入税率无需改动逻辑,仅仅须要在税率数组中加入就可以。

Array.prototype.contains = function(obj) {var i = this.length;while (i--) {if (this[i] === obj) {return true;}}return false;
}
var countryes=['3','5','6','11','17'];
var ret=countryes.contains('5') // return true
ret=   countryes.contains('15')// return false


转载于:https://www.cnblogs.com/gcczhongduan/p/5139686.html

返回
顶部