為什么加入了parselnt后無運行結果,不加則有結果?
<!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 ys=document.getElementById("select").value;
?????? switch(ys){
?????????? case "+":
?????????????? document.getElementById("fruit").value=parselnt(num1)+parselnt(num2);//這樣寫沒有反應
?????????????? break;
?????????? case "-":
????????????? document.getElementById("fruit").value=num1-num2;//這樣寫就能有答案出來
?????????????? break;
?????????? case "*":
????????????? document.getElementById("fruit").value=parselnt(num1)*parselnt(num2);//這樣寫沒有反應??????????????
?????????????? break;
?????????? case "/":
????????????? document.getElementById("fruit").value=parselnt(num1)/parselnt(num2);//這樣寫沒有反應??????????????
????????????? break;
????????? ?
?????? }
?? }
? </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>
2018-07-26
parseInt后面三個字母是Int轉換為整形
parselnt寫錯了哈
2018-07-24
parseInt 這個單詞里面的大寫I? 不是小寫L。。 小寫l與大寫I一模一樣。。你注意一下。。