[英]How to pass value using a tag to another page?
how can i get the h1 value and td values when a tag is clicked to another page? 单击标签到另一页时,如何获取h1值和td值?
<table>
<tr>
<td>
<h1>Book 1</h1>
</td>
</tr>
<tr>
<td>Chapter 1</td>
<td>100 pages</td>
<td><a href="newpage.html"></a></td>
</tr>
</table>
The data can be traversed between pages using GET
or POST
. 可以使用
GET
或POST
在页面之间遍历数据。 If using GET
, you need to pass the data as query string parameter
using jQuery/javascript
and receive it at the other end. 如果使用
GET
,则需要使用jQuery/javascript
将数据作为query string parameter
传递,并在另一端接收它。 If using POST
you need to submit the form and retrieve the same on the next Page 如果使用
POST
,则需要提交表单并在下一页上检索它。
You need to give those tags an ID and then use JavaScript to get their value and create a link. 您需要给这些标签指定一个ID,然后使用JavaScript获取它们的值并创建一个链接。
<table> <tr> <td> <h1 id="header">Book 1</h1> </td> </tr> <tr> <td id="val1">Chapter 1</td> <td id="val2">100 pages</td> <td><a id="link" href="newpage.html">Submit >></a></td> </tr> </table> <script> function generateLink() { var query = "h1=" + encodeURIComponent(document.getElementById("header").innerHTML) + "&val1=" + encodeURIComponent(document.getElementById("val1").innerHTML) + "&val2=" + encodeURIComponent(document.getElementById("val2").innerHTML); document.getElementById("link").href = "newpage.html?" + query; } generateLink(); </script>
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.