我怎样才能让jQuery直接转到< h2 id =" id-name">? [英] How I can I make jQuery go directly to <h2 id="id-name">?

查看:77
本文介绍了我怎样才能让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';

这篇关于我怎样才能让jQuery直接转到&lt; h2 id =&quot; id-name&quot;&gt;?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆