我有一个由jquery选项卡组成的html页面。每个选项卡都从另一个html页面加载数据。我在容器html页面中设置了一个全局变量,我想在其选项卡中访问它。我怎么做?我试过window.var,window.parent.var,this.var等但是什么都没有用。我附上了代码。善意的帮助。
容器html页面。
<html>
<head>
<link type="text/css" href="../../css/ui-lightness/jquery-ui-1.8.14.custom.css" rel="Stylesheet" />
<link type="text/css" href="./methodeditor.css" rel="stylesheet" />
<script type="text/javascript" src="../../js/jquery-1.5.1.min.js"></script>
<script type="text/javascript" src="../../js/jquery-ui-1.8.14.custom.min.js"></script>
<script>
$(function() {
$( ".tabs" ).tabs({cache:true});
});
</script>
<script>
var method = " ";
function setmethod(m) {
method = m;
}
function loadtabs(){
method = window.parent.method;
setmethod(method);
$("#oven").load('oven.html');
$("#detectors").load('detectors.html');
$("#inlets").load('inlets.html');
}
</script>
</head>
<body>
<form id="editor" action="method.php" method="POST" >
<div class="editor">
<div class="tabs">
<ul>
<li><a href="#oven">Temperature</a></li>
<li><a href="#detectors">Timing</a></li>
<li><a href="#inlets">Vial and Loop</a></li>
</ul>
<div id="oven" ></div>
<div id="detectors" ></div>
<div id="inlets"> </div>
</div>
<script>
loadtabs();
</script>
</form>
</div>
</body>
</html>
oven.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Untitled Document</title>
<script>
function getvalues() {
file = window.method;
//file = m;
file = "./method/"+file;
var xmlhttp = new XMLHttpRequest();
xmlhttp.open("GET", file, false);
xmlhttp.setRequestHeader('Content-Type', 'text/xml');
xmlhttp.send("");
xmldoc = xmlhttp.responseXML;
etimenode = xmldoc.getElementsByTagName("method")[0].childNodes[1].childNodes[1];
etime = etimenode.textContent;
document.getElementById("etime").value = etime;
}
</script>
</head>
<body>
<input type="checkbox" name="oventemp" value="ON" />Oven Temperature
Equilibrium time <input type="text" id="etime" />
<script>
getvalues();
</script>
</body>
</html>
答案 0 :(得分:0)
您可以在加载页面的字符串中包含所需的变量,例如:
setmethod(method);
$("#oven").load('oven.html?var1=' + myvar1 + '&var2=' + myvar2 );
然后在oven.html中,您可以使用方法similar to these将这些方法作为全局变量来获取,这些变量将在该已加载页面的范围内起作用: