gpt4 book ai didi

javascript - 除非我警告变量,否则我的事件将无法正常工作?为什么?

转载 作者:行者123 更新时间:2023-11-28 16:09:27 25 4
gpt4 key购买 nike

我有两个事件:onFocus (saveOld) 和 OnChange (showPoints)。当用户聚焦于下拉列表时,我使用 jquery.data 函数来保存下拉列表的旧值。当用户更改下拉列表的值时,我检查旧值是否大于当前值。如果是这样,我会相应地调整总数。但这仅在我从 onChange 中的 .data 函数获取旧值后发出警报时才有效。如果没有警报,什么也不会发生。

function showPoints(pointCategory, ddlAmount, name){
old = jQuery.data(document.body,name);

alert(old);

var Points = parseInt($('p#points').html());

if(old > ddlAmount){
diff = old - ddlAmount;
currentPoints = Points + (diff * pointCategory);
}else{
currentPoints = Points - (ddlAmount * pointCategory);
}
$('p#points').html(currentPoints);
}//showPoints

function saveOld(oldAmount, name){
$(document.body).data(name,oldAmount);
}

如果没有 showPoints() 中的警报,这将无法正常工作。出了什么问题?

编辑:请注意,我已经在应该发出警报的地方尝试了 this.delay(1000) 。还是没有成功。

最佳答案

尝试将 onfocus 更改为 onclick,并将当前值保存到 showPoints 末尾的 .data 中,如下所示:

$('p#points').html(currentPoints);
$(document.body).data(name,currentPoints);

我会在 showPoints 函数中使用局部变量。

关于javascript - 除非我警告变量,否则我的事件将无法正常工作?为什么?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/13527367/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com