<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>appendChild</title>
</head>
<body>
<input type="text" id="text">
<input type="button" id="btn" value="创建">
<ul id="list"></ul>
<script>
var otx = document.getElementById('text');
var obtn = document.getElementById('btn');
var oul = document.getElementById('list');
obtn.onclick = function () {
var oli = document.createElement('li');
var ali = oul.getElementsByTagName('li');
oli.innerHTML = otx.value;
if (otx.value.length == 0 || otx.value == "") {
alert('请填写内容!');
// 这个这个主otx.value怎么去去限制
} else {
if (ali.length > 0) {
oul.insertBefore(oli, ali[0]);
otx.value = "";
} else {
oul.appendChild(oli);
otx.value = "";
};
};
};
</script>
</body>
</html>
1 个回复
catchcat - - 怨只怨人在风中
赞同来自: lopo1983 、神奇大忽悠