简体   繁体   English

通过<a>标签</a>重定向到链接<a>,而不是href属性?</a>

[英]Redirect to a link by <a> tag, as opposed to href attribute?

I have a form and a link. 我有一个表格和一个链接。 Instead of the link being something on the screen to click, I'd like to just go to it. 我不想直接在屏幕上单击链接,而是直接转到它。 I've tried redirecting to "#" or setting the form action to "#". 我尝试重定向到“#”或将表单操作设置为“#”。 But it does not seem to work. 但这似乎不起作用。 I need a method of opening or redirecting to a link by <a> or by its ID. 我需要一种通过<a>或按其ID打开或重定向到链接的方法。

<form method="post" name="form">
    Name search:
    <input id="ui" type="text" name="ui" />
    <input type="submit" class="Submit" value="submit" />
</form>

$ui = $_POST["ui"];

<a href="#" id="gallery_filter"
          data-filter=".<?php echo $ui; ?>"><?php echo $ui; ?></a>

To link to an a tag that is being used as an anchor (marking a point on the page), you can use the id preceeded by a # : 要链接到用作锚a标签(在页面上标记一个点),可以使用#前面的id:

<form method="post" name="form" action="my_page.php#gallery_filter">
  ...
</form>

<a id="gallery_filter">Without an href, this is an anchor not a link.</a>

You can't submit a form to a url that is only an anchor (eg action="#gallery_filter" ), but if you add it to the end of the URL then the browser will navigate to it correctly. 您不能将表单提交到仅作为锚的url(例如action="#gallery_filter" ),但是如果将其添加到URL的末尾,则浏览器将正确导航到该表单。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM