【发布时间】:2020-10-11 02:46:36
【问题描述】:
所以我有一个问题,无论何时---- 我单击一个数字,它会打印 (function numberone) 。 我点击一个 operator(.operators class[.multiply, .divide, .minus, .plus]) 。所以问题从这里开始。我单击另一个数字(函数 numbertwo)。 NUMBER1 部分和 NUMBER2 部分都印有数字 所以这是代码: JS FIDDLE:https://jsfiddle.net/idk_anything_pro/g53bsvm9/1/
请修复我的代码...❤ 我的代码是如果你想要的话:
<html>
<head>
<script src="https://code.jquery.com/jquery-3.5.1.min.js" integrity="sha256-9/aliU8dGd2tb6OSsuzixeV4y/faTqgFtohetphbbj0=" crossorigin="anonymous"></script>
<title>Calculator</title>
<style>
.modulus,
.equal,
.plus,
.minus,
.divide,
.multiply{
width: 57px;
height: 43px;
background-color: gold;
color: black;
margin: 5px;
text-align: center;
border: none;
font-weight: bold;
}
.zero,
.nine,
.eight,
.seven,
.six,
.five,
.four,
.three,
.two,
.one{
width: 57px;
height: 43px;
background-color: black;
color: white;
margin: 5px;
text-align: center;
font-weight: bold;
}
.display{
border: 1px black solid;
width: 268px;
height: 45px;
margin-left: 5px;
background-color: black;
color: white;
font-weight: bold;
margin-bottom: 3px;
}
</style>
</head>
<body>
<div>
<div class="display">
<span class="num1"></span>
<span class="operator"></span>
<span class="num2"></span>
</div>
<button class="one">1</button>
<button class="two">2</button>
<button class="three">3</button>
<button class="multiply">x</button>
<br>
<button class="four">4</button>
<button class="five">5</button>
<button class="six">6</button>
<button class="plus">+</button>
<br>
<button class="seven">7</button>
<button class="eight">8</button>
<button class="nine">9</button>
<button class="minus">-</button>
<br>
<button class="zero">0</button>
<button class="equal">=</button>
<button class="modulus">%</button>
<button class="divide">/</button>
</div>
<script>
if ($('.operator').is(':empty')){
numberone();
}
$('.minus').click(function(){
$(".operator").append("-");
numbertwo();
});
$('.multiply').click(function(){
$(".operator").append("x");
numbertwo();
});
$('.divide').click(function(){
$(".operator").append("÷");
numbertwo();
});
$('.plus').click(function(){
$(".operator").append("+");
numbertwo();
});
function numberone(){
$('.one').click(function(){
$(".num1").append(1);
});
$('.two').click(function(){
$(".num1").append(2);
});
$('.three').click(function(){
$(".num1").append(3);
});
$('.four').click(function(){
$(".num1").append(4);
});
$('.five').click(function(){
$(".num1").append(5);
});
$('.six').click(function(){
$(".num1").append(6);
});
$('.seven').click(function(){
$(".num1").append(7);
});
$('.eight').click(function(){
$(".num1").append(8);
});
$('.nine').click(function(){
$(".num1").append(9);
});
}
function numbertwo(){
$('.one').click(function(){
$(".num2").append(1);
});
$('.two').click(function(){
$(".num2").append(2);
});
$('.three').click(function(){
$(".num2").append(3);
});
$('.four').click(function(){
$(".num2").append(4);
});
$('.five').click(function(){
$(".num2").append(5);
});
$('.six').click(function(){
$(".num2").append(6);
});
$('.seven').click(function(){
$(".num2").append(7);
});
$('.eight').click(function(){
$(".num2").append(8);
});
$('.nine').click(function(){
$(".num2").append(9);
});
}
</script>
</body>
</html>```
【问题讨论】:
标签: javascript html jquery css function