This question is unlikely to help any future visitors; it is only relevant to a small geographic area, a specific moment in time, or an extraordinarily narrow situation that is not generally applicable to the worldwide audience of the internet. For help making this question more broadly applicable, visit the help center
                            
                        
                    
                
                                6年前关闭。
            
                    
var bucketId = $.cookie('bucketId');
console.log(bucketId);

var bucketIdNumber = parseInt(bucketId, 10);
console.log("bucketIdNumber " + bucketIdNumber);


在关于bucketId的代码中,返回“ 17”。
那么,为什么当我parseInt bucketId时会得到NaN?

最佳答案

如果我正确理解这一点,则上面的代码等效于:

var bucketId = '"17"';
console.log(bucketId);

var bucketIdNumber = parseInt(bucketId, 10);
console.log("bucketIdNumber " + bucketIdNumber);


在这种情况下,bucketIdNumber确实返回NaN。您将需要进一步解析此cookie,并删除所有内部引号。

10-05 21:31