神奇:js一个函数里定义了两个变量,其中一个变量在另一个函数里也能调用,另一个变量却不能调用
页面代码如下:
<!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>无标题文档</title>
<style>
html,body{height:100%;overflow:hidden;}
#popupcontent{
position: absolute;
visibility: hidden;
overflow: hidden;
border:1px solid #CCC;
background-color:#F9F9F9;
border:1px solid #333;
padding:5px;
margin:100px;
z-index:3;
}
#popup1{
position: absolute;
z-index:2;
background:url(images/graybg.png);
visibility: hidden;
}
.h1{ width:400px;height:36;font:32px 微软雅黑,PTSansNarrow,sans-serif;font-weight: bold;color: #6666FF; padding-bottom:16px;}
.main1{ width:424px; height:236; background:#FFFFFF;margin-top:100px;padding:10px;border:solid #33CCFF 1px;}
.input1{
border:#ffffff 0px solid;
background-Color: #FF0080;
color:#ffffff;
padding:0 5px 5px 0;
font:32px 微软雅黑,PTSansNarrow,sans-serif;
font-weight:bold;
width:100px;
}
</style>
<script type="text/javascript">
var baseText = null;
function showPopup(w,h){
var popup1=document.getElementById("popup1");
var popup = document.getElementById("popupcontent");
popup.style.width = w + "px";
popup.style.height = h + "px";
popup1.style.width="100%";
popup1.style.height="100%";
popup.style.visibility = "visible";
popup1.style.visibility = "visible";
}
function areacook() {
var popup = document.getElementById("popupcontent");
var radio1=document.getElementsByName("area");
for(var i=0;i<radio1.length;i++){
if (radio1.item(i).checked==true){
var exp = new Date();
exp.setTime(exp.getTime() + 30*24*60*60*1000);
document.cookie = "area" + "="+ escape(radio1.item(i).value) + ";expires=" + exp.toGMTString();
popup.style.visibility = "hidden";
popup1.style.visibility = "hidden";
break;
}
}
}
</script>
</head>
<body onload="showPopup(424,236);">
<center><div class="main1" id="popupcontent">
<div class="h1">选择区域</div>
<div>
<label class="input1"><input name="area" type="radio" checked="true" value="1" />金水区</label>
<label class="input1"><input name="area" type="radio" value="2" />中原区</label>
<label class="input1"><input name="area" type="radio" value="3" />管城区</label>
<br><br>
<label class="input1"><input name="area" type="radio" value="4" />高新区</label>
<label class="input1"><input name="area" type="radio" value="5" />经开区</label>
<label class="input1"><input name="area" type="radio" value="6" />惠济区</label>
<br><br>
<button onClick="areacook()">确 定</button>
</div>
</div></center>
<div id="popup1"></div>
<div>this is a test message.</div>
<br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br><br>
</body>
</html>