私は、チェックボックスで簡単なゲームを作ってるんだ、と私は彼らが勝つかの点を失っている場合は、ユーザーに伝えるために、いくつかのJavaScriptを置きます。このため私はこのスクリプトを作ったが動作していない、誰かがこれで私を助けてくれる?は、その後、
値が正常に変更されますが、メッセージは1つしか表示されません。
ありがとうございます!
$(document).ready(function(){
var theTotal = 0;
\t $("#one").on("click", function(){
\t \t if($(this).is(':checked')){
theTotal = Number(theTotal) + Number($(this).val());
$('.total').text("Total: "+theTotal); \t
\t \t } else {
theTotal = Number(theTotal) - Number($(this).val());
$('.total').text("Total: "+theTotal);
\t \t }
\t });
$("#two").on("click", function(){
\t \t if($(this).is(':checked')){
theTotal = Number(theTotal) + Number($(this).val());
$('.total').text("Total: "+theTotal); \t
\t \t } else {
theTotal = Number(theTotal) - Number($(this).val());
$('.total').text("Total: "+theTotal);
\t \t }
\t });
$("#three").on("click", function(){
\t \t if($(this).is(':checked')){
theTotal = Number(theTotal) + Number($(this).val());
$('.total').text("Total: "+theTotal); \t
\t \t } else {
theTotal = Number(theTotal) - Number($(this).val());
$('.total').text("Total: "+theTotal);
\t \t }
\t });
if (theTotal >= 4) {
$("#ok").show();
} else {
$("#ok").hide();
}
if (theTotal >= 7) {
$("#win").show();
} else {
$("#win").hide();
}
if (theTotal <= 3) {
$("#lose").show();
} else {
$("#lose").hide();
}
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<input id="one" type="checkbox" value="3">
<input id="two" type="checkbox" value="5">
<input id="three" type="checkbox" value="2">
<div id="win">You are winning!</div>
<div id="lose">You are losing!</div>
<div id="ok">You can do it better!</div>
<div class="total"></div>
ありがとう!偉大な作品と私は、感謝したかった効果が再びあります! = D – Ermac
@エルマック問題なし –