<section class="main-sect bg-color m-t-5 m-b-20 clearfix focus" style=" position: relative;"> <textarea style="resize: none;width: 100%" rows="3" cols="20" id="content" contenteditable="true" cursor-spacing="100">给小伙伴加油吧</textarea> </section>
<input id="num_rmb" class="num_rmb" type="number" value="10" placeholder="请输入数据" οnkeyup="this.value=this.value.replace(/[^\d.]/g,'')">
$("#content").on('focus',function () { document.getElementById('content').focus(); window.addEventListener('resize', function () { if (document.activeElement.tagName === 'TEXTAREA') { document.activeElement.scrollIntoView({behavior: "smooth"}) } }) }); $('#content').on('blur', function () { window.scrollTo(0,0); });
$(".num_rmb").on('focus',function () { document.getElementById('num_rmb').focus(); window.addEventListener('resize', function () { if (document.activeElement.tagName === 'INPUT') { document.activeElement.scrollIntoView({behavior: "smooth"}) } }) }); $('.num_rmb').on('blur', function () { window.scrollTo(0,0); });
借鉴:https://blog.csdn.net/weixin_40656367/article/details/83658832