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

标签 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">

最佳答案

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

关于jquery - 我需要获取第一个输入的值,然后添加+1,然后将总和放入文本字​​段,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53569188/

相关文章:

c# - javascript 中相同的 c# 代码是什么?

jquery - 添加内容时如何让容器的高度增加而不是降低?

html - CSS 中的第 n 个 child

html - overflow-y 不适用于媒体查询

jquery - 这些网站是如何在浏览器中全屏显示的,底部有一个了解更多按钮(让你自动进入页面下方)

javascript - 动画元素,但保持容器居中

jquery - 使用 JQuery 切换可拖动窗口

html - 根据较高的 sibling 扩展 child 高度( parent 高度设置为自动)

Javascript如何设置间隔时间停止滚动

html - z 索引问题 navmenu 不会重叠