<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>test</title>
</head>
<body>
<input type="text"><button>发送</button>
<ul></ul>
<script>
function getObj(arg){
return document.getElementsByTagName(arg)[0];
}
var input = getObj("input");
var button = getObj("button");
var ul = getObj("ul");
button.onclick = function(){
var value = input.value;
if(value == ""){
alert("不可以发送空文本");
}else{
var li = document.createElement("li");
li.innerHTML = value;
ul.appendChild(li);
input.value = "";
}
}
</script>
</body>
</html>