js练习题
Posted
tags:
篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了js练习题相关的知识,希望对你有一定的参考价值。
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>
以上是关于js练习题的主要内容,如果未能解决你的问题,请参考以下文章
Python练习册 第 0013 题: 用 Python 写一个爬图片的程序,爬 这个链接里的日本妹子图片 :-),(http://tieba.baidu.com/p/2166231880)(代码片段
js代码片段: utils/lcoalStorage/cookie
spring练习,在Eclipse搭建的Spring开发环境中,使用set注入方式,实现对象的依赖关系,通过ClassPathXmlApplicationContext实体类获取Bean对象(代码片段