js實現簡單計算器功能
?function count(){
? ? ? ?
? ? //獲取第一個輸入框的值
? ? var v1 =document.getElementById("txt1").value;
//獲取第二個輸入框的值
? ? var v2 =document.getElementById("txt2").value;
//獲取選擇框的值
? ? var v3 =document.getElementById("select").value;
//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
? ? ?var v4 =document.getElementById("fruit").value;
? ? switch(v3)
? ? {
? ? ? ? case '+':v4=parseInt(v1+v2) ?
? ? ? ? case '*':v4=parseInt(v1*v2)
? ? ? ? case '-':v4=parseInt(v1-v2) ?
? ? ? ? case '/':v4=parseInt(v1/v2) ??
? ? ? ? ? document.write(v4);
? ? }
? ? //設置結果輸入框的值?
? ??
? ?
? ?}
計算器,不會,求指教
2015-10-31
關鍵點:case控制語句的使用,js字符串拼接與字符串計算的區別,input框取值賦值