根據您的要求和根據註釋「$ x必須爲真,$ y OR $ z OR $ anyThing不正確」。您可能需要添加額外的代碼行。
請參考下面的代碼並測試它。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<script type="text/javascript" src="http://code.jquery.com/jquery.min.js"></script>
<script type="text/javascript">
$(document).ready(function(){
$('#testBtn').on('click', function(){
var xInput = $('#xInput').val(),
yInput = $('#yInput').val(),
zInput = $('#zInput').val();
if(xInput == 'true' && (yInput == 'false' && zInput == 'false')){
$('#result').text("X it 'true'; Y & Z are 'false'");
} else if(yInput == 'true' && (zInput == 'false' && xInput == 'false')){
$('#result').text("Y it 'true'; X & Z are 'false'");
} else if(zInput == 'true' && (yInput == 'false' && xInput == 'false')){
$('#result').text("Z it 'true'; X & Y are 'false'");
} else {
$('#result').text("Try Again...");
}
});
});
</script>
</head>
<body>
X: <input type="text" id="xInput">  
Y: <input type="text" id="yInput">  
Z: <input type="text" id="zInput">  
<br/>
<br/>
<button id="testBtn">Test If Condition</button>
<br/>
<br/>
Result: <span id="result"></span>
</body>
</html>
究竟是什麼要求?我建議你花一些時間在基礎知識上 – Satpal
第一個。我需要檢查一個變量是否爲真,以及一組變量是否爲真。例如。 $ x必須爲真並且$ y OR $ z OR $ anyThing不爲真 – Ayanize
'if(($ x ==='on')&&!($ y ==='on'|| $ z === '')')){'這可能不正確,但這更符合我如何去做。無論如何, 需要更多細節。 –