-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathcala1.html
More file actions
71 lines (55 loc) · 2.13 KB
/
cala1.html
File metadata and controls
71 lines (55 loc) · 2.13 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>比例计算器</title>
<style>
body { font-family: Arial, sans-serif; }
.calculator { width: 260px; margin: 10px auto; padding: 10px; border: 1px solid #ccc; border-radius: 5px; }
.calculator input { width: 50%; padding: 8px; margin: 5px 0; box-sizing: border-box; }
.calculator button { width: 100%; padding: 10px; background-color: #007BFF; color: white; border: none; border-radius: 4px; cursor: pointer; }
.calculator button:hover { background-color: #0056b3; }
.calculator .result { margin-top: 15px; font-size: 16px; }
*{margin:0;padding:0;}
.a{width: 120px;height: 30px;border:1px solid blue;}
.b{width: 255px;height: 30px;border:1px solid green;}
</style>
</head>
<body>
<div class="calculator">
<h2>比例计算器</h2>
<form id="ratioForm">
<label>
<div align="center">比例</div>
</label>
<div>
<p align="center">
<input type="number" class="a" name="number" id="ratioDenominator" value="16" required>
<input type="number" class="a" name="number2" id="ratioNumerator" value="9" required>
</p>
</div>
<input button type="button" value="计算" onClick="calculateRatio()" class="b">
<p>
<input type="number" id="number1" value="1920" class="b" required>
</p>
<p id="result"></p>
<!--
<button type="submit">计算</button>
-->
</form>
<div>
</div>
</div>
<script>
function calculateRatio() {
var number1 = parseFloat(document.getElementById('number1').value);
var numerator = parseFloat(document.getElementById('ratioNumerator').value);
var denominator = parseFloat(document.getElementById('ratioDenominator').value);
var ratio = numerator / denominator;
var result = number1 * ratio;
document.getElementById('result').innerText = '结果: ' + result;
}
</script>
</body>
</html>