1
私はマネー管理プログラムで働いています。あなたの収入を入力しなければならない入力ボックスがあります。自分の番号を入力してEnterをクリックすると、その番号が横に表示されますが、別の番号を追加すると正しく追加されません。番号が正しく表示されない
HTML
<!DOCTYPE html>
<html>
<head>
<!-- Edit title -->
<title>Banking App</title>
<!-- Stylesheet -->
<link rel="stylesheet" type="text/css" href="assets/css/style.css">
</head>
<body>
<div class="main">
<header>
<h1>Bank Account Manager</h1>
</header>
<div class="displayInfo">
<div class="displayBalance">
<h2 class="displayBalanceTag">Balance: <span class="displayBalanceNumber"></span></h2>
</div>
</div>
<div class="inputInfo">
<center>
<input type="text" name="earned" placeholder="How Much Have You Earned?" class="earned">
<input type="text" name="spent" placeholder="How Much Have You Spent?" class="spent">
</center>
</div>
</div>
<!-- JQuery -->
<script src="https://ajax.googleapis.com/ajax/libs/jquery/3.1.0/jquery.min.js"></script>
<!-- Main.js -->
<script type="text/javascript" src="assets/js/main.js"></script>
</body>
</html>
JS
// VARIABLES
var balance; //stores users balance
var earnings; //stores users earnings
var earned = $(".earned"); //input users earnings
var spent = $(".spent"); //input users spendings
var displayBalanceNumber = $(".displayBalanceNumber"); //displays users balance
// START
$("document").ready(function() {
balance = 0;
init();
})
// INIT
function init() {
reset(); //resets everything
$(earned).bind("keypress", addEarnings);
}
function addEarnings(e) {
//check for keycode 13 (enter key)
if(e.which === 13) {
earnings = $(this).val(); //get value from input
balance = balance + earnings;
displayBalanceNumber.html(balance);
displayBalanceNumber.html(balance);
}
}
// RESET
function reset() {
displayBalanceNumber.html(balance); //make value inside balance holder to 0
}
どのように間違っていますか?あなたは何番号を入力し、何の結果を得ますか? – Mick
^また、あなたは何を期待していますか? – vlaz
'profit = + $(this)).val();' – adeneo