[英]When a link is clicked, I want to show a value/price on the next page
I have this code on page 1. All a tags have the same link.我在第 1 页上有此代码。所有 a 标签都有相同的链接。 If the user clicks on one link, the next page 2 is loaded.
如果用户单击一个链接,则会加载下一页 2。 I want to display the price of that id specific to that link to show on page 2.
我想显示特定于该链接的该 ID 的价格以显示在第 2 页上。
example: If the user clicks a link with id="saloon_price", the price on page 2 should appear Saloon: £50.示例:如果用户单击 id="saloon_price" 的链接,则第 2 页上的价格应显示为 Saloon: £50。 If the user clicks the link with id="mpv_price", the price on page 2 should appear MPV: £70.
如果用户单击 id="mpv_price" 的链接,则第 2 页上的价格应显示为 MPV:70 英镑。 Please help me to achieve this on page 2.
请帮助我在第 2 页实现这一目标。
I am very new to coding.我对编码很陌生。 And using Javascript.
并使用 Javascript。 Kindly help me with a simpler solution.
请帮助我提供更简单的解决方案。 Thanks
谢谢
<a id="saloon_price" href="/quotes/details"> Saloon: £50</a>
<a id="estate_price" href="/quotes/details">Estate: £60</a>
<a id="mpv_price" href="/quotes/details">MPV: £70</a>
You will propably need to use PHP or other server-side languages.您可能需要使用 PHP 或其他服务器端语言。 You can do this easily with forms.
您可以使用 forms 轻松完成此操作。 But you will need to run this on some kind of server.
但是您需要在某种服务器上运行它。
This will echo (type to document) the value of value attribute on the button...这将回显(键入以记录)按钮上 value 属性的值...
index.php:索引.php:
<form action="/quotes/details.php" method="post">
<button type="submit" name="price" value="£50" id="saloon_price"> Saloon: £50 </button>
...other buttons...
</form>
/quotes/details.php: /quotes/details.php:
...
<?php
$price = $_POST["price"];
echo "MPV: " . $price;
?>
...
You can use method="get"
and $_GET["price"]
if you want to see these values in url.如果您想在 url 中查看这些值,可以使用
method="get"
和$_GET["price"]
。
In the web, we pass values mainly using the URL, and read them again in the loaded page.在 web 中,我们主要使用 URL 传递值,并在加载的页面中再次读取。
<a id="saloon_price" href="/quotes/details?label=Saloon&value=£50"> Saloon: £50</a>
<a id="estate_price" href="/quotes/details?label=Estate&value=£60">Estate: £60</a>
<a id="mpv_price" href="/quotes/details?label=MPV&value=£70">MPV: £70</a>
And read this post for more details: How to get the value from the GET parameters?并阅读这篇文章了解更多详细信息: 如何从 GET 参数中获取值?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.