-
Notifications
You must be signed in to change notification settings - Fork 0
/
sample.html
60 lines (58 loc) · 1.88 KB
/
sample.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
<!DOCTYPE html>
<html lang="ja">
<head>
<link rel="stylesheet" href="https://stackpath.bootstrapcdn.com/bootstrap/4.1.3/css/bootstrap.min.css" integrity="sha384-MCw98/SFnGE8fJT3GXwEOngsV7Zt27NXFoaoApmYm81iuXoPkFOJwJ8ERdknLPMO" crossorigin="anonymous">
<script src="https://code.jquery.com/jquery-3.3.1.slim.min.js" integrity="sha384-q8i/X+965DzO0rT7abK41JStQIAqVgRVzpbzo5smXKp4YfRvH+8abtTE1Pi6jizo" crossorigin="anonymous"></script>
</head>
<body>
<div class="container">
<h4>QR Test</h4>
<div class="m-3 row">
<div class="col-6" style="background: #eeeeee;">
<div class="form-group">
<label>id</label>
<input class="form-control" id="id"/>
</div>
<div class="form-group">
<label>name</label>
<input class="form-control" id="name"/>
</div>
<div class="form-group">
<label>email</label>
<input class="form-control" id="email"/>
</div>
</div>
</div>
</div>
</body>
<script>
var words = '';
var scanning = false;
$(document).keypress(function(e) {
scanning = true;
if (e.charCode == 13) {
if (scanning) {
try {
var obj = JSON.parse(words);
setInput(obj);
} catch (e) {
alert(words)
}
words = '';
scanning = false;
}
return;
}
if (scanning) {
var key = String.fromCharCode(e.charCode);
words = words + key;
}
});
function setInput(obj) {
console.log(obj)
$('#id').val(obj.id)
$('#name').val(obj.name)
$('#email').val(obj.email)
}
</script>
</html>