求幫忙找錯
? ?<input type='button' value=' = ' onlick=count() /> <!--通過 = 按鈕來調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->?
? ?<input type='text' id='fruit' ?/> ??
?</body>
</html>
下面是我的代碼,我查看了無數(shù)遍都不知道是哪兒錯了
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? ?var num1= document.getElementById("txt1").value;
? ? ?var num2= document.getElementById("txt2")).value;?
? ? ?var way=document.getElementById("select").value;
? ? ?var res="";
? ? ?switch(way){
? ? ?case"+":
? ? ? ? res=parseInt(num1)+parseInt(num2);?
? ? ? ? break;
? ? ?case"-":
? ? ? ? res=parseInt(num1)-parseInt(num2);?
? ? ? ? break;
? ? ?case"*":
? ? ? ? res=parseInt(num1)*parseInt(num2);?
? ? ? ? break;
? ? ?default:
? ? ? ? res=parseInt(num1)/parseInt(num2); ??
? ? ?}
? ? ?document.getElementById("fruit").value=res;
? ?}
? </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' />?
2015-02-22
?我想問一下res=parseInt(num1)+parseInt(num2); 里parseInt是什么意思?不能直接res=num1+num2嗎?
2015-02-11
? ?
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? ?var num1= document.getElementById("txt1").value;
? ? ?var num2= document.getElementById("txt2").value; ?
? ? ?var way=document.getElementById("select").value; ?
var res=0;
? ? ?switch(way){
? ? ?case"+":
? ? ? ? res=parseInt(num1)+parseInt(num2);?
? ? ? ? break;
? ? ?case"-":
? ? ? ? res=parseInt(num1)-parseInt(num2);?
? ? ? ? break;
? ? ?case"*":
? ? ? ? res=parseInt(num1)*parseInt(num2);?
? ? ? ? break;
? ? ?default:
? ? ? ? res=parseInt(num1)/parseInt(num2); ??
break;
? ? ?}
? ? ?document.getElementById("fruit").value=res;
? ?}
? </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(txt1.value,txt2.value);' /> <!--通過 = 按鈕來調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->?
? ?<input type='text' id='fruit' ?/> ??
?</body>
</html>
2015-02-10
? ?<input type='button' value=' = ' onlick=count() />
????應(yīng)該是 onclick="count();"