0
我試圖讓它可以點擊一個按鈕,然後點擊^
,然後點擊另一個按鈕,它會將第一個號碼提高到第二個號碼的權力。提高權力給我的問題
代碼:
$(document).ready(function() {
var testNumLength = function(number) {
if (number.length > 9) {
totaldiv.text(number.substr(number.length - 9, 9));
}
};
var number = "";
var newnumber = "";
var operator = "";
var totaldiv = $("#total");
totaldiv.text("0");
$("#numbers a").not("#clear,#clearall").click(function() {
number += $(this).text();
totaldiv.text(number);
testNumLength(number);
});
$("#operators a, #side a").not("#equals, #decimal").click(function() {
operator = $(this).text();
newnumber = number;
number = "";
totaldiv.text("0");
if ($(this).attr('id') === "sqrt") {
operator = "sqrt";
$("#equals").click();
}
});
$("#clear,#clearall").click(function() {
number = "";
totaldiv.text("0");
if ($(this).attr("id") === "clearall") {
newnumber = "";
}
});
//Add your last .click() here!
$("#equals").click(function() {
if (operator === "+") {
number = (parseInt(number, 10) + parseInt(newnumber, 10)).toString(10);
} else if (operator === "-") {
number = (parseInt(newnumber, 10) - parseInt(number, 10)).toString(10);
} else if (operator === "÷") {
number = (parseInt(newnumber, 10)/parseInt(number, 10)).toString(10);
} else if (operator === "×") {
number = (parseInt(newnumber, 10) * parseInt(number, 10)).toString(10);
} else if (operator === "sq") {
number = (Math.pow(parseInt(newnumber, 10), parseInt(number, 10))).toString(10);
} else if (operator === "sqrt") {
number = newnumber;
number = Math.sqrt(parseFloat(number, 10)).toString(10);
}
totaldiv.text(number);
testNumLength(number);
number = "";
newnumber = "";
});
$('#decimal').click(function() {
var numOfDecs = 0;
for (var i = 0; i < number.length; i++) {
if (number[i] === ".") {
totaldiv.text(number[i]);
}
}
if (numOfDecs === 0) {
number.append('.');
totaldiv.text(number);
testNumLengh(number);
}
})
});
這裏是一個小提琴: https://jsfiddle.net/fqdxkL4y/3/
它只是將保持第二號有,而不是顯示結果。