請問加引號和不加引號的區(qū)別?
<!DOCTYPE html>
<html>
?<head>
? <title> 事件</title> ?
? <script type="text/javascript">
? ?function count(){
? ? var num1=document.getElementById("txt1").value;
? ? var num10=parseInt('num1');
? ? var num2=document.getElementById("txt2").value;
? ? var num20=parseInt('num2');
? ? var no1=document.getElementById("select").value;
? ? var no2;
? ? switch(no1){
? ? ? ? case '+':
? ? ? ? no2=num10+num20;
? ? ? ? break;
? ? ? ? case '-':
? ? ? ? no2=num10-num20;
? ? ? ? break;
? ? ? ? case '*':
? ? ? ? no2=num10*num20;
? ? ? ? break;
? ? ? ? default:
? ? ? ? no2=num10/num20;
? ? };
? ? ?document.getElementById('fruit').value=no2;
? ? //獲取第一個輸入框的值
//獲取第二個輸入框的值
//獲取選擇框的值
//獲取通過下拉框來選擇的值來改變加減乘除的運算法則
? ? //設置結果輸入框的值?
? ?}
? </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()"/> <!--通過 = 按鈕來調用創(chuàng)建的函數(shù),得到結果-->?
? ?<input type='text' id='fruit'/>?
?</body>
</html>
2015-10-02
num1是個變量,它里面的值是個字符串
2015-09-30
var num10=parseInt('num1');這樣輸入,結果是“NaN”;把引號去掉,就正常了。加引號不是表示字符串嗎,而num1本來就是字符串?有點疑惑