<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml"><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8" /><title>事件</title><script type="text/javascript">function count(){ var txt1,txt2,select,result; txt1=parseInt(document.getElementById('txt1').value); txt2=parseInt(document.getElementById('txt2').value); 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; } result=document.getElementById('fruit').value; }</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' /> <iput type='button' value=' = ' onclick='count()'/> <input type='txt' id='fruit'/> </body></html>
这段代码有什么问题吗?怎么在浏览器里面显示出来没有等于号“=”
你的"="的那个input拼错了啊。。
谢谢,以后得多注意了!
多谢指点,按你说的改过后计算机确实可以运行了!可是我还是不是很明白,为什么
result=document.getElementById('fruit').value和
document.getElementById('fruit').value=result的运行结果不一样?
这里确实错了,可是改回来了,计算器还是无法运行,点击等于号没有结果输出,还有错,求指点!
汗,惭愧,我总是犯些低级错误,多谢大虾!
有什么不一样吗?
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>事件</title>
<script type="text/javascript">
function count(){
var txt1,txt2,select,result;
txt1=parseInt(document.getElementById('txt1').value);
txt2=parseInt(document.getElementById('txt2').value);
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="txt" id="fruit"/>
</body>
</html>