window.onload=function()
{
var tt=document.getElementById('txt1').value
var tt2=document.getElementById('txt2').value
var sel=document.getElementById('select').value
var tt3=document.getElementById('txt3')
var dd=document.getElementById('btn1')
var result='';
switch(sel)
{
case "+":
result=parseInt(tt) + parseInt(tt2);
break;
case "-":
result=parseInt(tt) - parseInt(tt2);
break;
case "*":
result=parseInt(tt) * parseInt(tt2);
break;
default:
result=parseInt(tt) / parseInt(tt2);
}
dd.onclick=function()
{
tt3.value=result;
}
}
</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=' = ' id="btn1"/>
<input type='text' id='txt3' >
问题已解决,应该在onclick的时候,获取输入框的代码,否则值是"",result为NaN。有疑问可以问我
window.onload=function()
{
var result='';
var dd=document.getElementById('btn1')
dd.onclick=function(){
var tt=document.getElementById('txt1').value
var tt2=document.getElementById('txt2').value
var sel=document.getElementById('select').value
var tt3=document.getElementById('txt3')
switch(sel)
{
case "+":
result=parseInt(tt) + parseInt(tt2);
break;
case "-":
result=parseInt(tt) - parseInt(tt2);
break;
case "*":
result=parseInt(tt) * parseInt(tt2);
break;
default:
result=parseInt(tt) / parseInt(tt2);
}
tt3.value=result;
}
}