1.创建table表格,要求: 点击某一行,则该行变色(选中)。
<!DOCTYPE html>
<html lang="en">
<head>
<meta charset="UTF-8">
<title>创建Table表格</title>
<script type="text/javascript">
function check(obj) {
var len = document.getElementsByTagName("tr").length;
for (var i = 0; i < len; i++) {
var temp = document.getElementsByTagName("tr")[i];
if (obj == temp) {
temp.style.background="yellow";
}else {
temp.style.background="";
}
}
}
</script>
</head>
<body>
<table width="50%" border="1" cellpadding="2" cellspacing="0" align="center">
<tr onclick="check(this);">
<th>学号</th>
<th>姓名</th>
<th>成绩</th>
</tr>
<tr onclick="check(this);">
<td>01</td>
<td>张三</td>
<td>98.5</td>
</tr>
<tr onclick="check(this);">
<td>02</td>
<td>李四</td>
<td>80.6</td>
</tr>
<tr onclick="check(this);">
<td>03</td>
<td>王五</td>
<td>89.5</td>
</tr>
</table>
</body> </html> 2.用下拉列表框实现省市级联效果。 <select> <option value=""></option> </select> 提示:使用数组
<!DOCTYPE html>
<html lang="en"> <head> <meta charset="UTF-8"> <title>下拉列表省市级联</title> <script type="text/javascript"> var city = [ ["西安","安康","宝鸡","汉中","商洛","铜川","渭南","咸阳","延安","榆林"], ["成都","阿坝州","巴中","达州","德阳"], ["太原","长治","大同","晋城","晋中"], ["济南","滨州","东营","德州","菏泽"] ];
function getCity() {
var nProvince = document.form1.province;
var nCity = document.form1.city;
var provinceCity = city[nProvince.selectedIndex - 1];
nCity.length = 1;
for (var i = 0; i < provinceCity.length; i++) {
nCity[i+1] = new Option(provinceCity[i],provinceCity[i]);
}
}
</script>
</head> <body> <form method="post" action="" name="form1"> 地区查找: <select name="province" onchange="getCity()"> <option value="0" >请选择省份</option> <option value="陕西">陕西</option> <option value="四川">四川</option> <option value="山西">山西</option> <option value="山东">山东</option> </select> <select name="city"> <option value="0">选择城市</option> </select> </form> </body> </html>