哪位大师帮我解答一下,为什么全局变量放函数外不行?
<script>
var txt1=parseInt(document.getElementById("txt1").value);
var txt2=parseInt(document.getElementById("txt2").value);
var se=document.getElementById("vu").value;
var d;
function result(){
switch(se){
case "+":
d=txt1 + txt2;
break;
case "-":
d=txt1 - txt2;
break;
case "*":
d=txt1 * txt2;
break;
case "/":
d=txt1 / txt2;
break;
}
document.getElementById("sum").value=d;
}
</script>
<input type="text" id="txt1">
<select id="vu">
<option value="+">+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
</select>
<input type="text" id="txt2">
<input type="button" value="=" onclick="result()">
<input type="text" id="sum">