简体   繁体   English

单击链接时,我想在下一页上显示价值/价格

[英]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.

相关问题 点击链接时需要显示弹出页面 - Need to show popup page when clicked the link 如何将我点击的值传递给下一页 - How to pass the value that I clicked to next page 我想在单击该标签时传递锚标签内的文本并在定向页面上显示相同的文本 - I want to Pass the text inside anchor tag when clicked on that tag and to show the same text on the directed page 页面加载时隐藏div,单击链接时显示 - Hide div when the page is loaded and show when link is clicked 如何将单击链接的值传递到另一个页面并在跨度中显示它 - How to pass a value of a clicked link to another page and show it in a span 单击链接我们时显示每个页面的内容 - show content of each page when link us clicked 如何修改此程序,我想获得下一页链接 - How to modify this program, i want get the next page link 单击链接并显示选项卡时,BS 3获取数据属性值 - BS 3 getting data attribute value when a link is clicked and tab on show 当用户单击链接转到另一个网站时,我该如何请求用户留下。 但是,如果他们要访问我的网站上的其他页面,则没有要求? - How can I request a user to stay, when they clicked a link to go another website. But no request if they want to go another page on my website? 我想在单击按钮时显示不同的图像 - i want to show a different image when button is clicked
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM