我用Jquery手机在手机上设计了一个网页。我有一张桌子和几张照片。在错误的情况下,我将随机值填充到表中的列中。在单击图像时,表中的特定列值应该会增加(在这里,我使用了第4列)。在这里,在单击图像时,特定的列值会增加。
但问题是,当我单击图像时,列值从0开始增加。我需要的是,它必须从现有的列值增加。
var currentAdjustment = null;
var val = 0;
var beginAdjust = function(amount) {
currentAdjustment = amount;
setTimeout(checkAdjust, 100);
};
var checkAdjust = function() {
if (currentAdjustment !== null) {
makeAdjustment(currentAdjustment);
setTimeout(checkAdjust, 200);
}
};
var makeAdjustment = function(amt) {
val += amt;
$('#TableRowID td:nth-child(4)').text(val);
};
$('.upperArrow').bind('touchstart', function(){
var CurrentColumnVal = $("#TableRowID td:nth-child(4)").text();
beginAdjust(1);
}).bind('touchend', function(){
currentAdjustment = null;
});我可以获得字符串格式的现有列值(CurrentColumnVal)&尝试从那里增加,这是不起作用的。
发布于 2013-09-10 06:09:08
var thisIsAString = "2";
thisIsAString = thisIsAString + 1; // equals "21" (String concatenation)
var stringCastToNumber = Number("2"); // parseInt("2") would do as well
stringCastToNumber = stringCastToNumber + 1; // equals 3您的CurrentColumnVal指向一个字符串。把它投给一个数字。
发布于 2013-09-10 05:50:41
请将字符串中的增量值解析为parseInt(val)。
https://stackoverflow.com/questions/18711324
复制相似问题