计算器
function count(){
var inp1 = parseFloat(document.getElementById('inp1').value);
var inp2 = parseFloat(document.getElementById('inp2').value);
var symbol = document.getElementById('select').value;
console.log(symbol)
switch(symbol){
case '+':
document.getElementById('inp3').value = parseInt(inp1)+parseInt(inp2);
break;
case '-':
document.getElementById('inp3').value = parseInt(inp1)-parseInt(inp2);
break;
case '*':
document.getElementById('inp3').value = parseInt(inp1) *parseInt(inp2);
break;
case '/':
document.getElementById('inp3').value = parseInt(inp1)/parseInt(inp2);
break;
}
}
用到的方法:
parseInt() 函数可解析一个字符串,并返回一个整数。
parseFloat() 函数可解析一个字符串,并返回一个浮点数。
该函数指定字符串中的首个字符是否是数字。如果是,则对字符串进行解析,直到到达数字的末端为止,然后以数字返回该数字,而不是作为字符串。