1 回答

TA貢獻(xiàn)1條經(jīng)驗(yàn) 獲得超1個(gè)贊
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8" />
<title>表格添加與鼠標(biāo)移動(dòng)</title>
<script type="text/javascript">
function tab() {
var pli = document.getElementById("first");
var sli = document.createElement("tr");
sli.innerHTML = "<td>" + document.getElementById("input1").value + "</td>" +
"<td >" + document.getElementById("input2").value + "</td>" +
"<td ><p onclick='del(this)'>刪除</p></td>";
pli.appendChild(sli);
sli.onmouseenter = showColor;
sli.onmouseleave = hideColor;
document.getElementById("input1").value = "";
document.getElementById("input2").value = "";
}
function del(e) {
var o = e.parentNode.parentNode;
o.parentNode.removeChild(o);
}
var color = ['#4fbbfd', '#c9fd74', '#ff75ca'];
function showColor(e) {
var childNodes = e.target.childNodes;
for (var i = 0; i < childNodes.length; i++) {
childNodes[i].style.backgroundColor = color[i]
}
}
function hideColor(e) {
var childNodes = e.target.childNodes;
for (var i = 0; i < childNodes.length; i++) {
childNodes[i].style.backgroundColor = '#fff';
}
}
</script>
</head>
<body>
<p>在下面輸入框輸入標(biāo)題</p>
<input id="input1" type="text" value="">
<p>在下面輸入框中輸入你想輸入的內(nèi)容</p>
<textarea id="input2" name="" cols="30" rows="30"></textarea>
<input type="button" value="點(diǎn)我玩啊" onclick="tab()">
<table id="first" width="auto" ; height="auto" ; border="1" ; cellspacing="0" ;>
<tr>
<th width="200px">標(biāo)題</th>
<th width="500px">內(nèi)容</th>
<th>操作</th>
</tr>
</table>
</body>
</html>
看一下是否符合你的問(wèn)題?
添加回答
舉報(bào)