-
Notifications
You must be signed in to change notification settings - Fork 0
/
dp.html
34 lines (32 loc) · 1.12 KB
/
dp.html
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
<!DOCTYPE html>
<html lang="zh-CN">
<head>
<meta charset="UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>DP 计算器</title>
<script>
function calculateDP() {
// 获取用户输入的值
const resolution = parseFloat(document.getElementById('resolution').value);
const dpi = parseFloat(document.getElementById('dpi').value);
// 计算 dp
const dp = resolution / (dpi / 160);
// 显示结果
document.getElementById('result').innerText = `结果: ${dp.toFixed(2)} dp`;
}
</script>
</head>
<body>
<h1>DP 计算器</h1>
<form onsubmit="event.preventDefault(); calculateDP();">
<label for="resolution">分辨率 (px):</label>
<input type="number" id="resolution" name="resolution" value="1220" required>
<br>
<label for="dpi">屏幕密度 (dpi):</label>
<input type="number" id="dpi" name="dpi" value="446" required>
<br>
<button type="submit">计算 DP</button>
</form>
<p id="result">结果: </p>
</body>
</html>