これは簡単な電卓練習の部分的なコードです:誰かが私に説明することができます!このjqueryのlockButton
私の理解から!ブール値を反転するので、lockButtonsはfalseに設定されているため、最初のif文でtrueになりますか?しかし、後でif check =の下で、lockButtonsをtrueに設定して、数字が入力されなくなるようにしましたが、おそらく単純ですが、私の周りを頭で囲むことはできません。
var firstNumber = "";
var secondNumber = "";
var operator = "";
var result = 0;
var hasNumber = false;
var firstNumberComplete = false;
var lockButtons = false;
// Check if any button is clicked...
$(document).on("click", "button", function() {
// Checks if it's a number and that its not the end of the calculation ("!lockButtons")
if ($(this).hasClass("number") && !lockButtons) {
// We'll then set our "hasNumber" variable to true to indicate that we can proceed in selecting an operator.
hasNumber = true;
// If we haven't received an operator yet...
if (firstNumberComplete === false) {
// Then grab the number of the value clicked and build a string with it
firstNumber += $(this).attr("value");
// Print the number to the firstPage
console.log(firstNumber);
// Print it to the div
$("#first-number").html(firstNumber);
}
// If we have received an operator already...
else {
// Grab the number of the value clicked and build a string with it
secondNumber += $(this).attr("value");
// Print the number to the firstPage
console.log(secondNumber);
// Print it to the div
$("#second-number").html(secondNumber);
}
}
// Checks if its an operator (but not "=")
if ($(this).hasClass("operator") && hasNumber && !lockButtons) {
firstNumberComplete = true;
// Set the visual to show the operator's symbol
$("#operator").html("<h1>" + $(this).text() + "</h1>");
operator = $(this).attr("value");
}
// Checks if the equal button has been pressed. If so...
if ($(this).hasClass("equal")) {
// Lock the keyboard from being clicked
lockButtons = true;
'!lockButtons'は' lockButtons'の値を変更しません – bejado
var lockButtonsがまだfalseであり、true、lockButtonsがまだfalseであるかどうかをチェックするだけですか? –
'if(!lockButtons)'は 'lockButtons'が' false'かどうかを調べます。大声で言ってください: "もしlockButtonsでなければ" – bejado