(function( $, undefined ) {
/**
* IP与Number的相互转换
*/
$.ip = {};
$.ip.ipToNumber = function(ip) {
var ips = 0, numbers = ip.split(".");
for (var i = 0; i < 4; ++i) {
ips = ips << 8 | parseInt(numbers[i]);
}
return ips;
}
$.ip.numberToIp = function(number) {
var ip = [];
for (var i = 3; i >= 0; i--) {
ip[i] = number & 0xff;
number = number >> 8;
}
return ip.join(".");
}
})(jQuery);
如果未定义$.ip,会报错,ipToNumber和numberToIp是$.ip的属性,所以必须要存在这个对象