js内部变量外部调用

<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title></title>
<script>
var str1 = 0;
var str2 = 0;
/*1、定义单选按钮函数*/
function aCheck1(id) {
str1 = document.getElementById(id).value;
}
/*2、定义复选框函数*/
function test(can) {
str2 = can;
}
/*3、书写查询按钮函数*/
function caxun() {
alert(str1);
alert(str2);
}
</script>
</head>
<body>
<table>
<tr height="50px">
<td width="40%" align="center">
<input type="radio" name="RadioGroup1" value="1" id="ok1" onclick="aCheck1('ok1')" />
<font size="5" style="font-family: 仿宋;">男</font>
<input type="radio" name="RadioGroup1" value="2" id="ok2" onclick="aCheck1('ok2')" />
<font size="5" style="font-family: 仿宋;">女</font>
</td>
</tr>
<tr height="50px">
<td align="center">
<select onchange="test(this.value)" style="font-size: x-large; font-family: '仿宋';">
   <option value="1" >一</option>
   <option value="2" >二</option>
   <option value="3" >三</option>
   <option value="4" >四</option>
   <option value="5" >五</option>
</td>
</tr>
<tr height="50px">
<td width="30%" align="center">
<input type="button" value="查询" onclick="caxun()" style="font-size: x-large;font-family: '仿宋';" />
</td>
</tr>
</table>
<br />
<br />
</body>
</html>

猜你喜欢

转载自blog.csdn.net/tianzhen620/article/details/79931943