10-17
今天上午主要是講了昨天布置的作業,我感覺現在我對這一塊的理解真的是不夠,用的很生硬。
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>無標題文檔</title>
<script>var td_obj;
function tan(obj){
td_obj=obj;
//var tanchuang = document.getElementById("zs");
obj.innerHTML = prompt("shuru");
document.getElementById(‘div‘).style.display=‘block‘;
obj.setAttribute(‘abc‘,‘abc‘)
}
function td(){
document.getElementsByTagName("td");
var tdd = document.getElementsByTagName("td");
for(var i = 0; i<tdd.length; i++){
tdd[i].setAttribute(‘onclick‘,‘tan(this)‘)
}
}
function jc(){
var tdaaa = document.getElementsByTagName(‘td‘);
for(var i =0; i<=tdaaa.length;i++){
var saa = tdaaa[i].getAttribute(‘abc‘);
if(saa == "abc"){
tdaaa[i].style.fontWeight = "bold";
tdaaa[i].removeAttribute("abc");
}
}
}
function bh(){
td_obj.style.color = "red";
var dd = document.getElementById("div");
dd.style.display = "none";
}
function addcol(){
// 1、找到父元素(往這裏面添加元素)
var tableObj = document.getElementById("tbb");
// 2、創建元素 tr td創建td元素 創建tr元素
var trObj = document.createElement("tr");
for(var i = 0; i<4;i++){
var tdObj = document.createElement("td");
tdObj.innerHTML = "李四";
// 把td元素放到tr元素裏面
trObj.appendChild(tdObj);
}
// 3、把tr放到父元素
tableObj.appendChild(trObj);
var dd = document.getElementById("div");
}
</script>
</head>
<body>
<table id="tbb" border="1" width="80%" height="100px" cellpadding="0" cellspacing="0">
<tr>
<th>姓名</th>
<th>性別</th>
<th>年齡</th>
<th>班級</th>
</tr>
<tr>
<td onclick="td()" id="zs">張三</td>
<td>女</td>
<td>99</td>
<td>11</td>
</tr>
</table><div id="div" id="anniu" style="display:none">
<button onclick="jc()">加粗</button>
<button onclick="bh()">變紅</button>
</div>
<button onclick="addcol()">添加</button>
</body>
</html>
10-17