輸出結(jié)果為NAN 求大神解答
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
?? function jc(){
?????? var tt1=document.getElementById("txt1").value;
??? //獲取第一個(gè)輸入框的值
??? var tt2=document.getElementById("txt2").value;
??? //獲取第二個(gè)輸入框的值
??? var tt3=document.getElementById("select").value;
?? ?var jg= "";
??? //獲取選擇框的值
??? switch(tt3){
??????? case"+":
??????? jg=parseInt("tt1") + parseInt("tt2") ;
??????? break;
??????? case"-":
??????? jg=parseInt("tt1") - parseInt("tt2");
??????? break;
??????? case"*":
??????? jg=parseInt("tt1") * parseInt("tt2");
??????? break;
??????? case"/":
??????? jg=parseInt("tt1") / parseInt("tt2");?? ?
???? ?
??? }
?? ?
???? document.getElementById("fruit").value=jg;
?? }
? </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="jc()"/> <!--通過 = 按鈕來調(diào)用創(chuàng)建的函數(shù),得到結(jié)果-->
?? <input type='text' id='fruit'/>? ?
?</body>
</html>
結(jié)果一直未NAN,想知道錯(cuò)在哪
2016-05-30
在parseInt("tt1")不需要引號(hào)?