我怎样才能让jQuery直接转到< h2 id =" id-name">?
我想让jQuery直接导航(无动画需要)到我传入变量的id。
I want to make jQuery navigates directly (no animation need) to a id that I pass in a variable.
我有各种标记,如 id =content
, id =edit
, id =...
是< h2>
标题。使用PHP进行验证我将输出一个变量,如 var NAVIGATE_TO =<?php echo $ where_failed;?>
,我想将网站移动到 id
position。
I have various marks like id="content"
, id="edit"
, id="..."
that are <h2>
titles. Doing validation with PHP I will output a variable like var NAVIGATE_TO = <?php echo $where_failed;?>
and I want to move the website to that id
position.
如果我这样做 domain.tld / page#edit
或 #content
但是使用jQuery,因为当我加载页面时,我的PHP框架不允许我指示哈希。
Like if I do domain.tld/page#edit
or #content
but with jQuery because when I load the page my PHP framework doesn't allow me to indicate the hash.
您可以设置 location.hash
到 id
您需要浏览器滚动到:
You can set location.hash
to the id
you need the browser to scroll to:
window.location.hash = '#edit';