我想要这个,如果我在 text1 上输入 2015,text2 应该显示 2016
2 回答
MMMHUHU
TA贡献1834条经验 获得超8个赞
function onkey() {
var year1 = document.getElementById("year1");
var s = year1.value;
var year2 = document.getElementById("year2");
year2.value = +s + 1;
}
Smart猫小萌
TA贡献1911条经验 获得超7个赞
也许你只想这样做:
let doc, html, bod, I; // for use on other loads
addEventListener('load', ()=>{
doc = document; html = doc.documentElement; bod = doc.body; I = id=>doc.getElementById(id);
const year1 = I('year1'), year2 = I('year2');
year1.oninput = function(){
let v = this.value;
if(v.match(/^[0-9]+$/)){
year2.value = +v+1;
}
else if(v === ''){
year2.value = '';
}
}
}); // end load
<input id='year1' type='number' value='' />
<input id='year2' type='number' value='' />
- 2 回答
- 0 关注
- 106 浏览
添加回答
举报
0/150
提交
取消