<!DOCTYPE html><html> <head> <title> 事件</title> <script type="text/javascript"> function count() { var txt1=parseInt(document.getElementById('txt1').value); var txt2=parseInt(document.getElementById('txt2').value); var result=''; var select=docuemnt.getElementById('select').value; switch(select) { case '+': result=txt1+txt2; break; case '-': result=txt1-txt2; break; case '*': result=txt1*txt2; break; case '/': result=txt1/txt2; break; } document.getElementById('fruit').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=' = ' onclick="count()"/> <!--通过 = 按钮来调用创建的函数,得到结果--> <input type='text' id='fruit' /> </body></html>
2 回答

慕莱坞9220042
TA贡献377条经验 获得超508个赞
你好:
这行有错,“docuemnt”这个写错了,应该是“document”就可以了
var select=docuemnt.getElementById('select').value;
改正后代码:
<!DOCTYPE html> <html> <head> <title> 事件</title> <script type="text/javascript"> function count() { var txt1=parseInt(document.getElementById('txt1').value); var txt2=parseInt(document.getElementById('txt2').value); var result=''; var select=document.getElementById('select').value; switch(select) { case '+': result=txt1+txt2; break; case '-': result=txt1-txt2; break; case '*': result=txt1*txt2; break; case '/': result=txt1/txt2; break; } document.getElementById('fruit').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=' = ' onclick="count()"/> <!--通过 = 按钮来调用创建的函数,得到结果--> <input type='text' id='fruit' /> </body> </html>
望采纳!

qyy2499760117_叶子
TA贡献188条经验 获得超91个赞
var select=docuemnt.getElementById('select').value; 这句的docuemnt写错了,写对就有结果了,你用谷歌,按F12调试就能看到了。
添加回答
举报
0/150
提交
取消