根据单击的按钮更改文本内容 [英] Changing text content depending on button clicked

查看:36
本文介绍了根据单击的按钮更改文本内容的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有点像初学者,但是我的目标是根据在另一页面上单击的按钮来更改网页的标题.

I am sort of a beginner at this, but my objective is to have the header of my webpage changing, depending on what button was clicked on another page.

更准确地说,我有一个网页,上面有7个按钮,代码如下:

More precisely, I have a webpage with 7 buttons on it coded like this:

<form action="contribution.html">
    <input type="submit" style="margin-right: 80px;margin-top: 25px;" value="I contribute">
</form>

所有按钮都指向相同的"contribution.html"页面,但是我希望该页面的标题根据用户单击的按钮而有所不同.一定要有一种方法,而不必为每个按钮创建7个不同的"contribution.html"页面.我想.

All of the buttons lead to the same "contribution.html" page, but I would like the header of that page to be different depending on what button the user clicked. There must be a way to do this without creating 7 different "contribution.html" pages for each button... I assume.

任何人都可以帮忙吗?

推荐答案

使用服务器端语言和< a> 标签代替表单.在PHP中,它将如下所示:

Use a server-side language and <a> tags instead of a form. In PHP it will look something like this:

<a href="/contribution.php?sum=10">10$</a>
<a href="/contribution.php?sum=20">20$</a>
<a href="/contribution.php?sum=30">30$</a>

然后在 contribution.php 上,您可以从 $ _ GET ['sum'] 中获取请求数据并采取相应的行动.

Then on contribution.php you can get the request data from $_GET['sum'] and act accordingly.

这篇关于根据单击的按钮更改文本内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆