-
Notifications
You must be signed in to change notification settings - Fork 0
/
创建li
32 lines (32 loc) · 902 Bytes
/
创建li
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
<!DOCTYPE html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8"/>
<title></title>
<meta charset="utf-8" />
<script>
window.onload = function () {
var oBtn = document.getElementById('btn1');
var oUl = document.getElementById('ul1');
var oTxt=document.getElementById('txt1');
oBtn.onclick = function () {
var oLi = document.createElement('li');
var aLi = document.getElementsByTagName('li');
oLi.innerHTML = oTxt.value;
//oUl.appendChild(oLi);
if (aLi.length > 0) {
oUl.insertBefore(oLi, aLi[0]);
}
else {
oUl.appendChild(oLi);
}
}
}
</script>
</head>
<body>
<input id="txt1" type="text"/>
<input id="btn1" type="button" value="创建li">
<ul id="ul1"></ul>
</body>
</html>