我正在做家庭作业,我遇到了一个问题,我知道你们可以提供帮助。我正在使用 jQuery 并编写了我的第一个按钮。在我转向其他人之前,我正在尝试对其进行测试,因为一旦我理解了第一个,就很容易做到。我还必须为用户编写代码以输入基本颜色,但我已在代码中对此进行了注释。
<!DOCTYPE html>
<html lang="en">
<head>
<title>Calculations</title>
<script src="https://code.jquery.com/jquery-3.5.1.min.js"></script>
<script>
$(document).ready(function(){
$("#addition").click(function){
var intVal1 = parseInt($("#inputValue1").val());
var intVal2 = parseInt($("#inputValue2").val());
//var colorString = $("#colorSelection").val();
var total = intVal1 + intVal2;
$("#result").html(total);
}
});
</script>
</head>
<body>
<p>Value 1: <input type="number" id="inputValue1"></p>
<p>Value 2: <input type="number" id="inputValue2"></p>
<!--<p> Color: <input type="text" id="colorSelection"></p>-->
<p>Choose an operation below:</p>
<p>
<button type="button" id="addition">+</button>
<button type="button" id="subtraction">-</button>
<button type="button" id="multiply">*</button>
<button type="button" id="divide">/</button>
</p>
<p id="result"></p>
</body>
</html>
谢谢, 李
答案 0 :(得分:1)
function(){
$("#addition").click(function() { //this line
alert("Hi");
var intVal1 = parseInt($("#inputValue1").val());
var intVal2 = parseInt($("#inputValue2").val());
//var colorString = $("#colorSelection").val();
var total = intVal1 + intVal2;
$("#result").html(total);
}) //this line
});