如何添加#hash点击元素 [英] How to add #hash clicking to an element

查看:143
本文介绍了如何添加#hash点击元素的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

当我在 http://www.mywebsite.com/ 打开我的页面时,我拥有此jQuery代码:

When I open my page at http://www.mywebsite.com/ where I have this jQuery code :

$('#locSlideButton2').click(function() {

});

我想单击 locSlideButton2 元素,向网址添加散列(例如#example),而不进行任何重定向。

I'd like, clicking on the locSlideButton2 element, add an hash (such as #example) to the url, without make any redirect.

我该怎么做?

推荐答案

使用普通旧式香草JS:

Using plain old vanilla JS:

window.location.hash='example';

window.location上的MDN

这篇关于如何添加#hash点击元素的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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