使用空白链接但不跳转到页面顶部 [英] Use a blank link but not jump to top of page

查看:92
本文介绍了使用空白链接但不跳转到页面顶部的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在使用空白链接通过Jquery切换div,在链接中我有一个空白链接,允许您单击文本以切换div,但是当您单击切换文本时页面跳转到顶部。有没有办法防止这种情况?

I'm using a blank link to toggle a div through Jquery and in the link I have a blank link which allows you to click on the text to toggle the div but when you click toggle text the page jumps to the top. Is there a way to prevent this?

<a href="#" id="searchAnchor">Search Options</a>


推荐答案

使用<输入如果您不想要链接的功能,请键入=button> 。根据自己的喜好设计样式。

Use an <input type="button"> if you don't want the functionality of a link. Style it to look however you like.

(或者,在事件对象上调用 preventDefault(),但是仍然留给你一个不是链接的链接。)

(Alternatively, call preventDefault() on the event object, but that still leaves you with a link that isn't a link).

这篇关于使用空白链接但不跳转到页面顶部的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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