我想把我从 id 得到的值变成一个数字并加一,然后将新值传递给 dosomething()
函数以供使用。当我尝试这个并且值为 1 时,我得到 11 而不是 2。
$('.load_more').live("click",function() { // When user clicks
var newcurrentpageTemp = $(this).attr("id") + 1;// Get id from the hyperlink
alert(parseInt(newcurrentpageTemp));
dosomething();
});
最佳答案
假设你是正确的并且你的 id 是一个正确的数字(没有任何其他文本),你应该解析 id 然后加一:
var currentPage = parseInt($(this).attr('id'), 10);
++currentPage;
doSomething(currentPage);
关于jquery - 将字符串转换为数字并加一,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7674475/