在隐藏锚标记之前关注 url

发布于 2025-01-01 10:57:13 字数 242 浏览 2 评论 0原文

我有一个自动完成搜索表单,或多或少类似于 Facebook 上使用的表单,我开始输入内容,然后会显示一个姓名列表。 我为这些名字创建了链接,以便您可以打开他们的个人资料页面。 我还在搜索表单的输入字段“onblur”上提供了一个功能,我在其中隐藏了包含所有名称的自动完成 div。这样,当我在其外部单击时,它就不会保持可见。现在唯一的问题是,当我单击其中一个名称时,页面不会重定向到锚标记的个人资料页面,即使光标在悬停时确实发生变化。

有人有什么想法吗?

I have an autocomplete search form, more or less like the one used on facebook, where I start typing and a list of names shows up.
I made links of each of these names so you can open their profile page.
I also have a function on the search form's input field 'onblur', where I hide the autocomplete div with all the names. So that when I click outside it, it doesn't stay visible. The only problem now is that when I click one of the names, the pages doesn't redirect to the profile page of the anchor tag, even though the cursor does change on hover.

Anybody any idea?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

眉黛浅 2025-01-08 10:57:13

这是因为您的隐藏事件会在实际单击元素之前删除列表。有几种解决方案。

首先,您可以使用 setTimeout 来隐藏

setTimeout( function() { /* hide list */ }, 500);

回答您的评论,不,您不能重新排序事件。所以你必须找到解决方法。有很多方法,但由于您使用的是 jQuery,所以我会这样做。

//you probably have something like this currently
$('element').blur( function() { $('results').hide(); });    

//change it to something like this
$('element').blur( function() { $('results').fadeOut(300); }); 

This is because your hide event removes the list before the element can actually be clicked. There are couple of solutions.

First you could use a setTimeout to hide

setTimeout( function() { /* hide list */ }, 500);

In answer to your comment, no, you can't reorder events. So you will have to find a work around. There are a number of methods, but since you are using jQuery I would do it this way.

//you probably have something like this currently
$('element').blur( function() { $('results').hide(); });    

//change it to something like this
$('element').blur( function() { $('results').fadeOut(300); }); 
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文