简体   繁体   English

谁能告诉我我的代码有什么问题

[英]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.

相关问题 谁能告诉我我的代码有什么问题? - Can anyone tell me what is wrong with my code? 谁能告诉我这个代码是干什么用的? - can anyone tell me what is this code for? 我的Jquery按钮-禁用/启用功能不起作用。 谁能告诉我怎么了? - My Jquery button- disable/enable function is not working. Can anyone tell me what's wrong? 谁能告诉我这个套接字事件有什么问题? - Can anyone please tell me what's wrong this socket event? 谁能告诉我这个switch语句(javascript)怎么了? - Can anyone tell me what's wrong with this switch statement (javascript)? 谁能告诉我这个脚本出了什么问题? - Can anyone tell me what's wrong with this script? 谁能告诉我这个简单的代码有什么问题? - Can anyone tell me whats wrong here in this simple code? 谁能告诉我这些黑客试图在我的网站上做什么? - Can anyone tell me what these hackers are attempting to do on my website? 地理定位脚本不起作用? 谁能帮助我我的代码有什么问题 - GeoLocation script not working ? can anyone help me what's wrong in my code 正则表达式不起作用。 我的代码有什么问题? 谁能帮我解决这个问题 - Regex doesn't work. What's wrong with my code? Can anyone help me fix this
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM