【问题标题】:getting NaN, not increment the attribute value获取 NaN,不增加属性值
【发布时间】:2014-05-29 18:21:17
【问题描述】:

alert($(this).attr("data-itemindex")); 给我'999999999999999003'
和alert(dataValue); 给出'NaN'

但是为什么?

我期待 '999999999999999004'

alert($(this).attr("data-itemindex"));
var dataValue = Number($(this).attr("data-itemindex")) + 1;
alert(dataValue);

【问题讨论】:

  • 使用parseInt 或parseFloat 代替Number
  • @enyce12 其实我的号码太大了
  • @techouse parsiInt 和 parseFloat 没有帮助我,我仍然收到NaN
  • 我明白了。数字太大了……

标签: javascript jquery html nan


【解决方案1】:

这是有效的

var dataValue="'999999999999"+("000"+(parseInt($(this).attr("data-itemindex").slice( -3 ),10) + 1).toString()).slice(-3)+"'";

【讨论】:

    【解决方案2】:

    如果你想试试这个:

    https://github.com/rauschma/strint

    使用示例:

    var strint = require("./strint");
    strint.add("9007199254740992", "1")
    //'9007199254740993'
    

    【讨论】:

      【解决方案3】:

      你的号码太大了。最大可能数量是:

      9 007 199 254 740 992
      

      看看这个question。

      【讨论】:

        猜你喜欢
        • 2013-05-08
        • 1970-01-01
        • 1970-01-01
        • 2012-08-10
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2015-06-26
        相关资源
        最近更新 更多