今天上午主要是讲了昨天布置的作业,我感觉现在我对这一块的理解真的是不够,用的很生硬。
<!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>