<腳本類型=“text/javascript”>
window.onload = function(){
var btn = document.querySelector('input');
var text = document.querySelector('textarea');
var list = document.querySelector('#list');
var color = ["red" ,"pink"];
var nub = 0;
btn.onclick = function(){
if(text.value.trim() == ""){
alert("打點字吧");
# return false;
}
var li = document.createElement("li");
li.innerHTML = text.value;
// li.className = color[nub%colors.length];
/* 判斷一個標籤已經被加,就讓一個標籤顯示出來,否則就添加*/
if(list.children[0]&&list.children[0] .className=="red"){
li.className = "pink";
} else {
li.className = "red";
}
var a = null;
li.onmouseover = function(){
if(a) {
a.style.display = "block";
} else {
a = document.createElement("a") ;
a.href = "javascript: ;";
a.className = "clos";
a.innerHTML = "刪除";
a.onclick = function (){
list.removeChild(this.parentNode);
};
this.appendChild(a);
}
};
li.onmouseout = function(){
a.style .display = "無";
} ;
list.insertBefore(li,list.children[0]);
text.value = "";
nub++;
};
};