我需要获取第一个输入的值,然后加上+1,然后将总和放入文本字​​段中

时间:2018-12-01 08:50:19

标签: jquery html

这是我的代码,但是在acadyearTo中输出NaN:

jquery:

<script>
$( document ).ready(function() {
    var sum = parseInt($('#acadyearFrom').val()) + 1;
$('#acadyearTo').val(sum);
 });
</script>

html:

<input type="text" name="acadyearFrom" maxlength="4"  id="acadyearFrom">
<input type="text" name="acadyearTo" maxlength="4" id="acadyearTo">

1 个答案:

答案 0 :(得分:2)

var sum = parseInt($('#acadyearFrom').val()) + 1; // getting data from one text box, converting into number and adding 1
$('#acadyearTo').val(sum); // setting data to another text box