求大佬幫忙看看哪里出錯了。
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
var t1=parseInt(document.getElementById("txt1").value);
var t2=parseInt(document.getElementById("txt2").value);
var t3=document.getElementById("select");
var jieguo;
function jisuan()
{
? ? if(t3=="+")
? ? {
? ? ? ? jieguo=t1+t2;?
? ? }
? ? else if(t3=="-")
? ? {
? ? ? ? jieguo=t1-t2;
? ? }
? ? else if(t3=="*")
? ? {
? ? ? ? jieguo=t1*t2;
? ? }
? ? else
? ? {
? ? ? ? jieguo=t1/t2;
? ? }
? ? document.getElementById("fruit").value=jieguo;
}
? </script>?
?</head>?
?<body>
? ?<input type='text' id='txt1' />?
? ?<select id='select'>
<option value='+'>+</option>
<option value="-">-</option>
<option value="*">*</option>
<option value="/">/</option>
? ?</select>
? ?<input type='text' id='txt2' />?
? ?<input type='button' value=' = ' onclick="jisuan()" />?
? ?<input type='text' id='fruit' /> ??
?</body>
</html>
2019-08-05
var t1=parseInt(document.getElementById("txt1").value);
var t2=parseInt(document.getElementById("txt2").value);
var t3=document.getElementById("select");
var jieguo;
這幾個變量定義要放到方法里面去,因為方法內無法調用方法外的變量