<!DOCTYPE?html>
<html>
<head>
<title>?new?document?</title>??
<meta?http-equiv="Content-Type"?content="text/html;?charset=utf-8"/>???
<script?type="text/javascript">?
//起始背景色函數(shù)
window.onload?=?function(){
var?trs?=?document.getElementsByTagName('tr');
for?(var?i?=?0;?i?<?trs.length;?i++){
setOver(trs[i]);
setOut(trs[i]);
};
}
//背景色函數(shù)
function?setOver?(obj)?{
obj.onmouseover?=?function(){
this.style.backgroundColor?=?"##f2f2f2"?
};
}
function?setOut?(obj)?{
obj.onmouseout??=?function(){
this.style.backgroundColor?=?"#fff"?
};;
}
//刪除函數(shù)
function?removeLine?(obj)?{
var?oG?=?obj.parentNode.parentNode.parentNode;
var?oP?=?obj.parentNode.parentNode;
oG.removeChild(oP);
}
//添加函數(shù)
function?newLine?()?{
var?stuName?=?prompt("enter?name","");
var?stuId???=?prompt("enter?number","");
var?objTr???=?document.createElement('tr');
objTr.innerHTML?=?
"<td>"+stuId+"</?td><td>"+stuName+"</?td><td><a?href?=?'javascript:;'?onclick?=?'removeLine(this)'?>刪除</?a></?td>?";
setOver(objTr);
setOut(objTr);
document.getElementById('table').lastChild.appendChild(objTr);
}
?
</script>?
</head>?
<body>?
<table?border="1"?width="50%"?id="table">
<tr>
<th>學(xué)號</th>
<th>姓名</th>
<th>操作</th>
</tr>??
<tr>
<td>xh001</td>
<td>王小明</td>
<td><a?href="javascript:;"?onclick?=?"removeLine(this)">刪除</a></td>???<!--在刪除按鈕上添加點(diǎn)擊事件??-->
</tr>
<tr>
<td>xh002</td>
<td>劉小芳</td>
<td><a?href="javascript:;"?onclick?=?"removeLine(this)">刪除</a></td>???<!--在刪除按鈕上添加點(diǎn)擊事件??-->
</tr>??
</table>
<input?type="button"?value="添加一行"?onclick="newLine()"??/>???<!--在添加按鈕上添加點(diǎn)擊事件??-->
</body>
</html>因?yàn)橄胍o新增項(xiàng)上加顏色,所以 聲明了一個(gè)setOver setOut 函數(shù),想要在創(chuàng)建新行的時(shí)候調(diào)用。但是就是無動(dòng)于衷啊。急死我了,求同學(xué)們指導(dǎo)??!
為什么背景顏色始終無動(dòng)于衷勒?捉急死了!
薛淞之
2015-10-04 20:44:47