猿问

如何自动递增,如果我在 text1 上键入 2015,text2 应该显示 2016。

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

德玛西亚99
浏览 108回答 2
2回答

MMMHUHU

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

Smart猫小萌

也许你只想这样做:let doc, html, bod, I; // for use on other loadsaddEventListener('load', ()=>{doc = document; html = doc.documentElement; bod = doc.body; I = id=>doc.getElementById(id);const year1 = I('year1'), year2 = I('year2');year1.oninput = function(){&nbsp; let v = this.value;&nbsp; if(v.match(/^[0-9]+$/)){&nbsp; &nbsp; year2.value = +v+1;&nbsp; }&nbsp; else if(v === ''){&nbsp; &nbsp; year2.value = '';&nbsp; }}}); // end load<input id='year1' type='number' value='' /><input id='year2' type='number' value='' />
随时随地看视频慕课网APP
我要回答