如何自动递增,如果我在 text1 上键入 2015,text2 应该显示 2016。有没有简单的方法?

how to auto increment, if I type 2015 on text1, text2 should display 2016. is there an easy way to this?

我想要这个,如果我在 text1 上输入 2015,text2 应该显示 2016

也许你只是想这样做:

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='' />

function onkey() {
 var year1 = document.getElementById("year1");
 var s = year1.value;
 var year2 = document.getElementById("year2");
 year2.value = +s + 1;
}