关于form表单过长,点击确定找到未填项并定位到此处
上代码,自辩,我是好使滴
heightToTop(ele){ let root = document.body; let height=0; do{ height+=ele.offsetTop; ele = ele.offsetParent; }while(ele!==root) return height; }, eleScrollError(){ this.$nextTick(()=>{ let isError=document.getElementsByClassName('is-error'); console.log(isError); // document.querySelector(".main2").scrollTo({behavior:"smooth",top:this.heightToTop(isError[0]) - 60},500); let container = isError[0].querySelector("input")||isError[0].querySelector("textarea"); container.focus(); }) }, //以下没试,自辩 scrollError(DOM){ this.$nextTick(()=>{ let container = document.querySelector(".main2"); container.scrollTo({behavior:"smooth",top:this.$refs[DOM].offsetTop},500); }) },
参考:https://blog.csdn.net/q140948940/article/details/115520524