如何使用来自选项卡中生成的链接列表的数据,然后在其他选项卡中使用它?
我有tab1.html
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./js/list.js"></script>
<title>Tab 1</title>
</head>
<body>
<h1>Here I fill the linked list with data</h1>
<button type="button" onclick="fillList();">Fill list</button>
<button type="button" onclick="testThisTab();">Test to print the linked list generated in this tab</button>
<a href="t2.html">Go to other page</a>
</body>
</html>
使用上述代码,我有一个按钮填充列表
,然后使用此按钮,我在JS中启动方法filllist
文件,然后我有一个按钮测试来打印此选项卡中生成的链接列表
,使用此按钮我测试链接列表正在工作,因为我进入了控制台:
List filled
5
1
6
3
2
然后我有一个超链接要去到TAB2.HTML
。
在tab2.html
我有:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./js/list.js"></script>
<title>Document</title>
</head>
<body>
<h1>Here I want to use the linked list generated in the other view</h1>
<button type="button" onclick="useOfMethosOfLinkedList();">print list data in console</button>
</body>
</html>
在上面的代码中,我想打印tab1.html
的链接列表的数据,但是当我按print时在控制台
按钮中列出数据,我不会在控制台中获得任何内容,也许是因为当我转动页面时,链接列表的数据会变得清晰。
我的JavaScript代码名称list.js
是:
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}
class LinkedList {
constructor() {
this.head = null;
this.size = 0;
}
empty() {
return this.head == null;
}
add(data) {
let aux = new Node(data);
if (this.empty()) {
this.head = aux
} else {
aux.next = this.head;
this.head = aux;
}
}
print() {
let aux = this.head;
while (aux != null) {
console.log(aux.data);
aux = aux.next;
}
}
}
let listl = new LinkedList();
function fillList() {
listl.add("2");
listl.add("3");
listl.add("6");
listl.add("1");
listl.add("5");
console.log("List filled");
}
function useOfMethodsOfLinkedList() {
listl.print()
}
function testThisTab() {
listl.print()
}
我正在寻找保存数据的信息,但它只是与API一起显示信息,但是我无法使用它,因此,如果可以帮助找到任何解决方案,我会非常感激。
I have tab1.html
:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./js/list.js"></script>
<title>Tab 1</title>
</head>
<body>
<h1>Here I fill the linked list with data</h1>
<button type="button" onclick="fillList();">Fill list</button>
<button type="button" onclick="testThisTab();">Test to print the linked list generated in this tab</button>
<a href="t2.html">Go to other page</a>
</body>
</html>
With the above code I have a button Fill list
, and with this button I start the method fillList
in my JS file, then I have a button Test to print the linked list generated in this tab
, with this button I test that the linked list is working because I get in console:
List filled
5
1
6
3
2
and then I have a hyperlink to go to the tab2.html
.
In tab2.html
I have:
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<script src="./js/list.js"></script>
<title>Document</title>
</head>
<body>
<h1>Here I want to use the linked list generated in the other view</h1>
<button type="button" onclick="useOfMethosOfLinkedList();">print list data in console</button>
</body>
</html>
In the above code I want to print the data of the linked list generated in tab1.html
, but when I press the print list data in console
button, I don´t get anything in console, maybe because when I turn the page the data of the linked list gets clear.
My javascript code name list.js
is:
class Node {
constructor(data) {
this.data = data;
this.next = null;
}
}
class LinkedList {
constructor() {
this.head = null;
this.size = 0;
}
empty() {
return this.head == null;
}
add(data) {
let aux = new Node(data);
if (this.empty()) {
this.head = aux
} else {
aux.next = this.head;
this.head = aux;
}
}
print() {
let aux = this.head;
while (aux != null) {
console.log(aux.data);
aux = aux.next;
}
}
}
let listl = new LinkedList();
function fillList() {
listl.add("2");
listl.add("3");
listl.add("6");
listl.add("1");
listl.add("5");
console.log("List filled");
}
function useOfMethodsOfLinkedList() {
listl.print()
}
function testThisTab() {
listl.print()
}
I were looking for information to save the data but it just appear information with API's, but I can´t use that, so if could help to find any solution I will be so grateful.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论