How to implement jump to <a name=... in post form
I have long list of products and in each product i have form:
<form action="index.php" method="post">
<input type="hidden" name="prodid" value="<?= $id ?>" />
...
</form>
I want to jump to product on call action like:
<a href="#prodid<?= $id ?>">jump to product</a>
...
<a name="prodid<?= $id ?>"></a>
but i must use post method. In get method I would use this:
<form action="index.php#prodid<?= $id ?>" method="get">
...
</form>
How to do it?
Using <a name="..."></a>
for a jump-mark is deprecated in HTML5 as the a
-element has no name
-attribute anymore. See here: HTML Anchors with 'name' or 'id'? and in the specs.
You can jump to anything on the site with a specified id
-attribute by adding the #[id]
to the URL (or creating a link like <a href="#[id]">jump</a>
).
Adding the hashtag does not have anything to do with GET or POST. It's just a Browser-Feature.
What about simple:
<form action="index.php#prodid<?= $id ?>" method="post">
<input type="hidden" name="prodid" value="<?= $id ?>" />
...
</form>
You will use both - hidden input and anchor in action.
I would think that you can still use #prodid=x
syntax even with "post" methods. POST
method only controls how the data is sent to the server.
When the browser displays the target page of the form, it will see the #anchor
and scroll the page accordingly. Moreover, you can submit the form without the tag and then inside your processing script have something like this:
// process everything as required
...
header("location: mypage.php#prodid=$prodid");
链接地址: http://www.djcxy.com/p/88998.html
上一篇: 固定页面标题重叠