使用 jquery 增加/减少字段的值

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/1366648/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-26 11:17:35  来源:igfitidea点击:

Increment/decrement the value of a field using jquery

jquery

提问by nash

I am getting a wrong output when i alert this, it shows '01'

当我警告这个时,我得到一个错误的输出,它显示“01”

<input type="hidden" id="hidNavigation" name="hidNavigation" value="0" />

alert($("#hidNavigation").val($("#hidNavigation").val() + 1));

I am a newbie using jquery, please help me how to increment/decrement values in jquery.

我是使用 jquery 的新手,请帮助我如何在 jquery 中增加/减少值。

Thanks, Nash

谢谢,纳什

回答by Darin Dimitrov

alert($("#hidNavigation").val(parseInt($("#hidNavigation").val()) + 1));

回答by madzohan

$("#hidNavigation").get(0).value++

Simply reposted from comment to @DarinDimitrov answer ... credits to @northamerican

简单地从评论转贴到@DarinDimitrov 回答...学分@北美