前端之家收集整理的这篇文章主要介绍了
Jquery数学加法,
前端之家小编觉得挺不错的,现在分享给大家,也给大家做个参考。
我正在尝试通过
jquery事件
添加,我正在
获取NaN.我错过了什么?
<input type="hidden" id="skillcount" name="skillcount" value="3" onchange="valueadd(this)"/>
function valueadd(ok){
var value=parseFloat($(this).val())+1;
}
代码应该是:
function valueadd(ok){
// "this" inside here refers to the window
var value=parseFloat(ok.value)+1;
}
内联onchange实际上是一个匿名函数:
function() {
//"this" inside here refers to the element
valueadd(this);
}
所以“this”是一个在valueadd范围内被称为“ok”的参数.正如其他人所说,你可能想要使用jquery的绑定,因此valueadd中的“this”将指向该元素.
原文链接:https://www.f2er.com/jquery/176989.html