[英]Can anyone tell me what is wrong in my code
what I did is I made 3 functions in js file which is being used by 2 html5 pages. 我所做的是我在js文件中做了3个功能,目前被2个html5页面使用。 In the two functions I am storing the values of the selected items in global variables ie from dropdown lists and want to display it in another page...but var returns a null value.
在这两个函数中,我将所选项目的值存储在全局变量中,即从下拉列表中存储,并希望将其显示在另一页中...但是var返回一个空值。
<!DOCTYPE html5>
<html>
<head>
<script type="text/javascript" src="123.js"></script>
</head>
<body>
<form>
Select your favorite browser:
<select id="city_list" onchange="city()">
<option></option>
<option>Google Chrome</option>
<option>Firefox</option>
<option>Internet Explorer</option>
<option>Safari</option>
<option>Opera</option>
</select>
<select id="blood_group" onchange="bloodGroup()">
<option></option>
<option>Google Chrome</option>
<option>Firefox</option>
<option>Internet Explorer</option>
<option>Safari</option>
<option>Opera</option>
</select>
</form>
</body>
</html>
File 2 文件2
<!DOCTYPE html5>
<html>
<head>
<script type="text/javascript" src="123.js"></script>
</head>
<body onload="answers()">
<form>
<p>Your favorite browser is: <input type="text" id="favorite2" size="20"></p>
<p>Your favorite browser is: <input type="text" id="favorite3" size="20"></p>
</form>
</body>
</html>
Javascript i use: 我使用的Javascript:
var bloodtype;
var whichcity;
function city()
{
var mylist=document.getElementById("city_list");
whichcity=mylist.options[mylist.selectedIndex].text;
document.getElementById("favorite").value=whichcity;
var selectedanswer=document.getElementById("city_list").selectedIndex;
}
function bloodGroup()
{
var mylist=document.getElementById("blood_group");
bloodtype=mylist.options[mylist.selectedIndex].text;
}
function getvalues()
{
document.getElementById("favorite2").value=whichcity;
document.getElementById("favorite3").value=bloodtype;
}
What you are trying to do is sharing data between two independent html documents. 您想要做的是在两个独立的html文档之间共享数据。 This is impossible without persistent storage since html itself has no concept of persistence.
如果没有持久性存储,这是不可能的,因为html本身没有持久性的概念。 Try the following:
请尝试以下操作:
Option 1: Get yourself a server, upload the files there and use a <form>
to send the data to the server (for example Apache ) 选项1:让您自己拥有一台服务器,将文件上传到那里,然后使用
<form>
将数据发送到服务器(例如Apache )
Option 2: Read more about local storage , a browser feature in HTML5 选项2:详细了解本地存储 (HTML5中的浏览器功能)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.