[英]Retrieve specific row from a table in another HTML file - Javascript
I was wondering if somebody could help me out with this one.我想知道是否有人可以帮助我解决这个问题。 I have 2 html pages, page1.html and page2.html.我有 2 个 html 页面,page1.html 和 page2.html。 page1.html has an text box, a button, and 3 labels. page1.html 有一个文本框、一个按钮和 3 个标签。 page2.html has a table called mytable that has this data. page2.html 有一个名为 mytable 的表,其中包含此数据。
Number Color Shape
1 Red Square
2 Blue Circle
3 Orange Triangle
On page1.html I am trying to input a number in the textbox, after hitting the button and will bring back the corresponding row into the 3 labels.在 page1.html 上,我试图在文本框中输入一个数字,点击按钮后,会将相应的行带回 3 个标签中。 So if I enter in 2, the 3 labels will show 2, Blue, Circle.因此,如果我输入 2,则 3 个标签将显示 2、Blue、Circle。 Any ideas?有任何想法吗? I researched all over and the closest I got was this code below.我进行了全面研究,我得到的最接近的是下面的代码。 Any help would be greatly appreciated.任何帮助将不胜感激。
page1.html第1页.html
<!DOCTYPE html>
<html>
<head>
<title>Acknowledgement</title>
</head>
<body>
<script>
var value1="value1";
var value2="value2";
var queryString = "?para1=" + value1 + "¶2=" + value2;
window.location.href = "page2.html" + queryString;
</script>
</body>
</html>
page2.html第2页.html
<!DOCTYPE html>
<html>
<head>
<title>Acknowledgement</title>
</head>
<body>
<h4>These are the data from page1.html.</h4>
<script>
var queryString = decodeURIComponent(window.location.search);
queryString = queryString.substring(1);
var queries = queryString.split("&");
for (var i = 0; i < queries.length; i++)
{
document.write(queries[i] + "<br>");
}
</script>
</body>
</html>
You can use localstorage or您可以使用本地存储或
Assign value in page 1 before navigation window.myobj={val1:"val1",val2:"val2"}导航前在第 1 页赋值 window.myobj={val1:"val1",val2:"val2"}
Get data on page 2 var mydata=window.myobj;获取第 2 页的数据 var mydata=window.myobj; console.log(mydata.val1);控制台.log(mydata.val1);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.