2015-02-24 193 views
0

爲什麼功能不想寫第二個按鈕與其他值的演示程序?第二個功能按下按鈕

function check(x){ 
 
\t if (x == 0,100) {return 1;} 
 
\t else { return 25;}; 
 
} 
 
function test2() { 
 
\t \t var y,input; 
 
\t \t input = document.getElementById("input2").value; 
 
\t \t y = check(input); 
 
\t \t $("#demo2").html(y); 
 
\t }
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<input type="number" id="input2"> 
 
<button id="but" onclick ="test2()">Try it</button> 
 
<p id="demo2"></p>

+0

這是什麼(如果(X == 0,100))是幹什麼的? – Vaibhav 2015-02-24 15:49:49

+0

是的,控制檯:意外的令牌如果 – 2015-02-24 15:53:20

回答

0

這是因爲你的支票()函數始終返回1,並在每次按下按鈕時,您的p被覆蓋。

你想在你的if()中實現什麼?

編輯

更改您如果到

if (x != '' && (x == 0 || x == 100)) 
+0

當我寫入輸入0或100函數檢查返回1到y。當我寫入輸入其他數字函數返回25到y。之後y是demo2的段落。 – 2015-02-24 16:06:23

+0

@ĽubomírSkirka看到我編輯的答案 – 2015-02-24 16:18:37

+0

編輯很好。謝謝。 – 2015-02-24 16:24:14

相關問題