Javascript进阶篇6-11的编程练习
<!DOCTYPE html> <html> <head> <meta charset="UTF-8"> <title>JS进阶篇编程练习</title> <script type = "text/Javascript"> function count(){ //获取第一个输入框的值,parseInt防止获取的为字符串 var txt1 = parseInt(document.getElementById("txt1").value); //获取第二个输入框的值 var txt2 = parseInt(document.getElementById("txt1").value); //获取选择框的值 var txt3 = document.getElementById("select").value; //获取通过下拉框来选择的值来改变加减乘除运算 switch(tet3){ case "+":sum = txt1 + txt2; break; case "-":sum = txt1 - txt2; break; case "*":sum = txt1 * txt2; break; case "/":sum = txt1 / txt2; break; } //设置输入框的值 getElementById("friut").value = sum; } </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 = "count()"/> <!--通过 = 按钮来调用创建的函数,得到结果--> <input type="text" id="fruit"/> </body> </html>
运行完点击=没结果啊?怎么回事呢?亲们