forked from hellokaton/write-readable-code
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathExample7.html
More file actions
50 lines (48 loc) · 1.28 KB
/
Copy pathExample7.html
File metadata and controls
50 lines (48 loc) · 1.28 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
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>Title</title>
</head>
<body>
<form>
<input type="text" id="input1" value="biezhi"/>
<input type="text" id="input2" value="abc"/>
<input type="text" id="input3" value=""/>
<input type="text" id="input4" value="80k"/>
<input type="text" id="input5" value="os7blue"/>
</form>
<script>
// var setFirstEmptyInput = function (new_value) {
// var found = false;
// var i = 1;
// var elem = document.getElementById('input' + i);
// while (elem != null) {
// if (elem.value === "") {
// found = true;
// break;
// }
// i++;
// elem = document.getElementById('input' + i);
// }
// if (found) {
// elem.value = new_value;
// }
// return elem;
// };
var setFirstEmptyInput = function (new_value) {
for (var i = 1; true; i++){
var elem = document.getElementById('input' + i);
if(elem == null){
return null;
}
if (elem.value === "") {
elem.value = new_value;
return elem;
}
}
return null;
};
</script>
</body>
</html>