var bucketId = $.cookie('bucketId');
console.log(bucketId);
var bucketIdNumber = parseInt(bucketId, 10);
console.log("bucketIdNumber " + bucketIdNumber);
在有关 bucketId 的代码中返回“17”。那么为什么当我 parseInt bucketId 得到 NaN 时?
var bucketId = $.cookie('bucketId');
console.log(bucketId);
var bucketIdNumber = parseInt(bucketId, 10);
console.log("bucketIdNumber " + bucketIdNumber);
在有关 bucketId 的代码中返回“17”。那么为什么当我 parseInt bucketId 得到 NaN 时?
If I'm understanding this correctly, the code above is equivalent to:
var bucketId = '"17"';
console.log(bucketId);
var bucketIdNumber = parseInt(bucketId, 10);
console.log("bucketIdNumber " + bucketIdNumber);
In which case, bucketIdNumber does return NaN. You will need to further parse this cookie, and remove any inner quotation marks.
bucketId
probably doesn't start with an integer.
If the first character cannot be converted to a number, parseInt() returns NaN.