刷新网页定位到特定位置

js刷新网页定位到特定位置


刷新网页后定位到特定位置 ,我们都知道可以在url 后面加上#id ,定位到网页的特定标签处,其中id就是你的id选择器名,今天练习时,突然犯囧了,如果事先不知道网址还怎么定位,百度了一下,haha,果然有相应的方法,那就是focus() 方法,关于它有两种写法,一种是HTML DOM中的写法

 <script>	document.getElementById("tel").focus(); </script>
  <input id="tel"  class="tel" name="tel" placeholder="请输入手机号码" type="tel" />
	  或者
	  function getFocus()
      {
 		 document.getElementById('tel').focus()
     }
     <input type="button" onclick="getFocus()"  id="tel" />

另外一种是jQuery的写法,这种写法记得在开头导入jQuery文件

<script type="text/javascript" >
	  			$("#tel").focus();
  </script>
  
	 // 你也可以加一个判定浏览器刷新的方法
	 
	 <script type="text/javascript" >
	  	window.onload=function(){
	  			$("#tel").focus();
	  	}
	  </script>
posted @ 2018-10-05 01:29  legendaryhaha  阅读(374)  评论(0编辑  收藏  举报