2011-10-19 20 views
0

I have long list of products and in each product i have form:如何實現跳轉到<a name=... in post 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?

+0

的技術是一樣的,它只取決於通過GET或POST ......我不understant得到變量問題在哪裏? – jackJoe

回答

5

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'?specs

您可以通過在網站上添加#[id](或創建鏈接,如<a href="#[id]">jump</a>)來跳轉到指定的id網站上的任何內容。

添加hashtag與GET或POST沒有任何關係。這只是一個瀏覽器功能。

+0

名稱僅在xhtml中被棄用,它在html中仍然有效。請參閱http://derickrethans.nl/html-name-attribute-deprecated.html和http://stackoverflow.com/questions/484719/html-anchors-with-name-or-id。 – Steve

+0

@Steve它沒有,HTML5中沒有'name'屬性 –

+0

呵呵,有趣的是,它實際上起作用,規範FTW! :) – Steve

0

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"); 
1

什麼簡單:

<form action="index.php#prodid<?= $id ?>" method="post"> 
    <input type="hidden" name="prodid" value="<?= $id ?>" /> 
    ... 
</form> 

您將同時使用 - 隱藏的輸入和錨行動。

0

使用以下語法創建爲每個產品頁面上的書籤:

<a name="prodid<?= $id ?>"> 
    <form action="index.php" method="post"> 
     <input type="hidden" name="prodid" value="<?= $id ?>" /> 
     ... 
    </form> 
</a> 

如果你正在寫的XHTML/HTML5拖放name屬性,那麼你可以使用:

<form action="index.php" method="post" id="prodid<?= $id ?>"> 
    <input type="hidden" name="prodid" value="<?= $id ?>" /> 
    ... 
</form> 
0

但我必須使用post方法。

不,你不需要那個。
GET方法沒問題。

0

對於類似項目的長長列表,我使用最多的方式是interator和前綴。這讓我在每一個項目是有序的上下文,每一個可與躍升至:<a href="#section24">Additionnal information</a>

相關問題