2017-10-08 114 views
-4

我在做一个方程式计算器。我想要做的就是提醒是否存在“C”值输入,因为如果存在“C”值,我想要做其他事情。即使有“C”值,它也会给我结果。请帮忙。jquery跳过我的if语句

$('#resultButton').click(function() { 
    var cValue = $("#cText").val(); 
    if (cValue == ""){ 
     var aValue = $("#aText").val(); 
     var bValue = $("#bText").val(); 
     var result = Math.sqrt((aValue*aValue)+(bValue*bValue)); 
     $('#result').text(result); 
    } 
    else { 
     alert('There is a C value'); 
    } 
}); 
+1

你应该看看[问]和[MCVE] – pvg

回答

2

“我希望它做的是提醒,如果有一个‘C’值输入”

我想你忘了,包括jQuery的或有什么地方错了你的HTML(你没不提供)。

见,它完美的作品以最小的HTML:

$('#resultButton').click(function() { 
 
    var cValue = $("#cText").val(); 
 
    if (cValue == ""){ 
 
     var aValue = $("#aText").val(); 
 
     var bValue = $("#bText").val(); 
 
     var result = Math.sqrt((aValue*aValue)+(bValue*bValue)); 
 
     $('#result').text(result); 
 
    } 
 
    else { 
 
     alert('There is a C value'); 
 
    } 
 
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> 
 
<input id="cText"> 
 
<button id="resultButton">Click</button>