实现的效果:
代码:
<!DOCTYPE html><html><head><meta charset="utf-8"><title></title><style type="text/css">.oul{width: 200px;height: 200px;margin: 100px auto;border: 1px solid #000000;position: relative;}.box{width: 150px;height: 150px;position: absolute;left: 0;right: 0;bottom: 0;top: 0;margin: auto;/* background-color: red; */display: flex;justify-content: space-between;align-items: center;}.ali{display: inline-block;width: 20px;height: 20px;text-align: center;}</style></head><body><div class="oul"><div class="box"><input type="text" maxlength="1" class="ali" autofocus="autofocus"/><input type="text" maxlength="1" class="ali" onclick="this.blur()"/><input type="text" maxlength="1" class="ali" onclick="this.blur()"/><input type="text" maxlength="1" class="ali" onclick="this.blur()"/></div></div><script type="text/javascript">var Oul=document.getElementsByClassName('box')[0]Oul.oninput=function(e){var e=window.event||evar tar=e.target || e.srcElement if(tar.nodeName=='INPUT' && tar.nextElementSibling!==null){tar.nextElementSibling.focus()}}</script></body></html>