代码之家  ›  专栏  ›  技术社区  ›  Arwed

增加Javascript变量的值?

  •  0
  • Arwed  · 技术社区  · 15 年前

    使用mootools处理链接单击事件。 在我的html中,我有一个带有此模式id的链接:toggle\ NUMBER例如toggle\ 1 现在我得到了这个和平的代码id

    var id = $(this.get('id').replace(togglePrefix,emptyPrefix)); 
    

    我的问题现在开始了:

    var togglePrefix = 'toggle_', boxPrefix = 'page_', emptyPrefix = '';
    

    现在我试着把这个数字增加一

    var id_new = parseInt(id)+1;
    

    但这不起作用,我不知道如何改变它!

    2 回复  |  直到 12 年前
        1
  •  0
  •   fuwaneko    15 年前

    var id_new = $(this).get('id').replace(togglePrefix, emptyPrefix) + 1;
    
        2
  •  0
  •   Chase Wilson    15 年前

    在侵入ID之前,您是否尝试过$(this).next()?