-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvw.html
78 lines (65 loc) · 2.16 KB
/
vw.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
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
72
73
74
75
76
77
78
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>vw</title>
<script src="./js/jquery.min.js"></script>
<script src="./js/bootstrap.min.js"></script>
<link rel="stylesheet" href="./css/bootstrap.min.css">
<link rel="stylesheet" href="./css/vw.css">
</head>
<body>
<div id="app">
<h1>vw计算器</h1>
<div class="btn-group" role="group" aria-label="Basic radio toggle button group">
<input type="radio" class="btn-check" name="btnradio" id="btnradio1" autocomplete="off" checked value="1920">
<label class="btn btn-outline-primary" for="btnradio1">PC</label>
<input type="radio" class="btn-check" name="btnradio" id="btnradio2" autocomplete="off" value="750">
<label class="btn btn-outline-primary" for="btnradio2">Mobile</label>
</div>
<div class="input-group input-group-sm">
<input type="number" class="form-control form-control-lg" aria-label="Sizing example input" />
<button type="button" class="btn btn-primary">计算</button>
</div>
<div class="jieguo">
</div>
</div>
</body>
<script>
$(document).ready(function () {
$('input[type=radio][name=btnradio]').change(function () {
jisuan()
})
})
function jisuan() {
var num = Number($('.form-control').val()) / Number($('input[type=radio][name=btnradio]:checked').val()) * 100
$('.jieguo').text(num.toFixed(4) + 'vw')
var Input = document.createElement('input');
Input.value = num.toFixed(4) + 'vw'
document.body.appendChild(Input);
Input.select(); // 选择对象
document.execCommand("Copy"); // 执行浏览器复制命令
Input.className = 'Input';
Input.style.display = 'none';
}
$('.input-group button').click(function () {
jisuan()
})
$('.form-control').keyup(function (event) {
console.log(event);
switch (event.keyCode) {
case 13:
jisuan()
}
})
$(document).keyup(function (event) {
console.log(event);
switch (event.keyCode) {
case 32:
$('.form-control').focus()
}
})
</script>
</html>