我正在使用jQuery来检索由输入按钮提交的值.该值应该是一个整数.我想将它递增一个并显示它.
// Getting immediate Voting Count down button id
var countUp = $(this).closest('li').find('div > input.green').attr('id');
var count = $("#"+countUp).val() + 1;
alert (count);
Run Code Online (Sandbox Code Playgroud)
上面的代码给了我一个连接的字符串.比如说值为3.我想得到4作为输出,但代码产生31.
如何将HTML输入值的数据类型更改为整数?
Aln*_*tak 18
要转换strValue为整数,请使用:
parseInt(strValue, 10);
Run Code Online (Sandbox Code Playgroud)
或一元运算+符.
+strValue
Run Code Online (Sandbox Code Playgroud)
注意radix参数,parseInt因为前导0会导致parseInt输入为八进制,输入010值为8而不是10
parseInt( $("#"+countUp).val() , 10 )
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
24135 次 |
| 最近记录: |