如何使用jQuery捕获对href值的单击
16lz
2021-01-22
I have the following HTML code in the backend, ie.
我在后台有如下的HTML代码。
<div class="navi">
<a class="" href="0"></a>
<a class="" href="1"></a>
<a class="" href="2"></a>
<a class="" href="3"></a>
</div>
Apologies for the basic question but I would like to use jQuery to capture the user's click when they only click on the href value of "0"
很抱歉这个基本的问题但是我想用jQuery捕获用户的点击当他们只点击href值"0"时
Basically want to hide a div called "info" when the user clicks on the where the href="0"
当用户点击href="0"时想要隐藏一个叫"info"的div
Unsure how to do?
不知道怎么办?
Thanks.
谢谢。
1 个解决方案
#1
8
You can use the attribute-equals selector, like this (though I don't think that's a valid href
):
您可以使用attribute-equals选择器,就像这样(尽管我不认为这是一个有效的href):
$("a[href=0]").click(function() {
$("#info").hide();
});
A better approach, if possible, would be to give the <a>
a better href
that points to the <div>
, like this:
如果可能的话,更好的方法是为< A >提供一个指向
的更好的href,如下所示:更多相关文章
- Yii - 加载ajax表单元素的用户端验证
- EasyUI动态展示用户信息
- 请教一下ajax代替frame在后台管理系统布局上应当怎么应用?
- j2ee的web项目,有最终的html代码(即f12看到的最终给用户浏览器展示
- golang写服务端程序,作为文件上传与下载的服务器。配合HTML5以网
- 维护Java应用程序的多种形式的用户指南
- 我正在尝试使用带有post方法的AJAX将用户名和密码发送到php文件
- iframe调用后台方法通过response返回html代码
- HTML5用户身份认证源代码:注册、登录、会话保持的解决方案