1 定位到input元素中
var element = document.getElementById(ys_id);//ys_id为传入的html元素的id element.focus();View Code
2 定位到div元素中
window.location.hash = "#"+ys_id;//ys_id是div元素d额id element.classList.add("focusColor");View Code
3 当鼠标移动到当前元素或离开当前元素的时候执行的函数
<div class="col-xs-2 div_css" onm ouseout="Out(this)"> <input class="input_css" autocomplete="off" placeholder="请输入" type="text" name="jgmc" id="jgmc" disabled> </div> //js //失去焦点 function Out(element) { var id = element.id; if(id == "icu" || id == "sscz" || id == "cyzd"){ window.location.hash = ""; } element.classList.remove("focusColor"); } //其中icu以及sscz等元素为div元素,之前光标定位使用的 //是window.location.hash = "#"+ys_id //则在让其失去光标的时候需要删除hash;View Code
标签:hash,元素,element,html,ys,JS,id,光标 From: https://www.cnblogs.com/daytoy105/p/16655933.html