如何根据输入字段更改链接?

发布于 2024-08-23 20:30:22 字数 137 浏览 13 评论 0原文

我正在设计我学校的网站,我想做一个“你在寻找什么”页面,只有一个输入框,人们可以在其中输入电话或其他东西,并且可以通过自动建议完成(这部分没问题)。然后,当用户单击“转到”时,该按钮会将他们带到搜索定义的页面,以便直接转到电话号码页面,反之亦然。你建议怎么做?

Im designing my school's website and I kind of want to do like a "What are you looking for" page with only an input box where people can enter in phone or something and it would be completed with autosuggest (got that part ok). Then when the user clicked go, the button would take them to the page defined by the search so it would go directly to the phone numbers page and vice versa. What would you suggest to do that?

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

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

发布评论

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

评论(3

情感失落者 2024-08-30 20:30:22

为了进行自我暗示,您可以使用 Ajax 概念。

For giving autosuggestion you can use Ajax concept.

自我难过 2024-08-30 20:30:22

也许最好的方法是编写一个附加到表单提交操作的函数。然后,您可以让该函数检查输入框的内容来决定应打开哪个页面。

您使用以下代码打开页面:

window.location = "http://www.WhateverSiteYouWant.com";

但是,您可以考虑使用下拉导航列表,而不是尝试猜测用户可能键入的所有内容。您可以在 http://www.thesitewizard.com/archive 中查看如何编写代码的示例/navigation.shtml

Google 可以为您提供更多这样的示例。

Probably the best way to do this is to write a function which is attached to the submit action of your form. Then, you can have that function examine the contents of the input box to decide which page should be open.

You open the page with the code:

window.location = "http://www.WhateverSiteYouWant.com";

However, rather than trying to guess what all a user might type, you might just consider using a dropdown navigation list. You can see an example of how to code one at http://www.thesitewizard.com/archive/navigation.shtml

Google can provide you with many more such examples.

空袭的梦i 2024-08-30 20:30:22

您可以通过将 window.location.href 设置为要重定向到的 URL 来完成此操作。因此,在按钮单击处理程序中,您可以执行以下操作:

window.location.href = "some_url";

You could do it by setting the window.location.href to the URL want to redirect to. So in your button-click handler, you do:

window.location.href = "some_url";
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文