function count(){ var a = document.getElementById("txt1").value; var b = document.getElementById("txt2").value; var c= document.getElementById("select").value; var result; if(c=="+"){ result = parseInt(a) + parseInt(b); } else if(c=="-"){ result = parseInt(a) - parseInt(b); } else if(c=="*"){ result = parseInt(a) * parseInt(b); } else{ result = parseInt(a) / parseInt(b); } document.getElementById("fruit").value = result; } function count() { var sum,x,y; x=5; y=6 sum=x+y; alert(sum);}为什么第一段a,b需要加上parseInt才能实现计算功能第二段不用 |