1.复选框案例
<body>
<table border="1px" width="500px" style="text-align: center;" align="center">
<tr>
<td>全选<input id="qx" type="checkbox" onclick="qx()"/></td>
<td><input name="da" type="checkbox" onclick="checkMonthYear(this,01,4,6)"/>1月</td>
<td><input name="da" type="checkbox" onclick="checkMonthYear(this,02,4,6)"/>2月</td>
<td><input name="da" type="checkbox" onclick="checkMonthYear(this,03,4,6)"/>3月</td>
<td><input name="da" type="checkbox" onclick="checkMonthYear(this,04,4,6)"/>4月</td>
<td><input name="da" type="checkbox" onclick="checkMonthYear(this,05,4,6)"/>5月</td>
<td><input name="da" type="checkbox" onclick="checkMonthYear(this,06,4,6)"/>6月</td>
</tr>
<tr>
<td>2008年<input name="da" type="checkbox" onclick="checkMonthYear(this,2008,0,4)"/></td>
<td><input value="200801" name="a" type="checkbox"/></td>
<td><input value="200802" name="a" type="checkbox"/></td>
<td><input value="200803" name="a" type="checkbox"/></td>
<td><input value="200804" name="a" type="checkbox"/></td>
<td><input value="200805" name="a" type="checkbox"/></td>
<td><input value="200806" name="a" type="checkbox"/></td>
</tr>
<tr>
<td>2007年<input name="da" type="checkbox" onclick="checkMonthYear(this,2007,0,4)"/></td>
<td><input value="200701" name="a" type="checkbox"/></td>
<td><input value="200702" name="a" type="checkbox"/></td>
<td><input value="200703" name="a" type="checkbox"/></td>
<td><input value="200704" name="a" type="checkbox"/></td>
<td><input value="200705" name="a" type="checkbox"/></td>
<td><input value="200706" name="a" type="checkbox"/></td>
</tr>
<tr>
<td>2006年<input name="da" type="checkbox" onclick="checkMonthYear(this,2006,0,4)"/></td>
<td><input value="200601" name="a" type="checkbox"/></td>
<td><input value="200602" name="a" type="checkbox"/></td>
<td><input value="200603" name="a" type="checkbox"/></td>
<td><input value="200604" name="a" type="checkbox"/></td>
<td><input value="200605" name="a" type="checkbox"/></td>
<td><input value="200606" name="a" type="checkbox"/></td>
</tr>
<tr>
<td>2005年<input name="da" type="checkbox" onclick="checkMonthYear(this,2005,0,4)"/></td>
<td><input value="200501" name="a" type="checkbox"/></td>
<td><input value="200502" name="a" type="checkbox"/></td>
<td><input value="200503" name="a" type="checkbox"/></td>
<td><input value="200504" name="a" type="checkbox"/></td>
<td><input value="200505" name="a" type="checkbox"/></td>
<td><input value="200506" name="a" type="checkbox"/></td>
</tr>
</table>
</body>
<script type="text/javascript">
function qx(){
var qx = document.getElementById("qx");
var as = document.getElementsByName("a");
for(var i = 0;i<as.length;i++){
as[i].checked = qx.checked;
}
}
function checkMonthYear(obj,v,a,b){
var as = document.getElementsByName("a");
for(var i = 0;i < as.length;i++){
var va = as[i].value;
if(va != 'on'){
var str = va.substring(a,b);
if(str == v){
das[i].checked = obj.checked;
}
}
}
}
</script>
2.随机器案例
<body>
<div>
<table align="center">
<tr><td id="a" class="tda">X</td><td id="b" class="tda">X</td><td id="c" class="tda">X</td></tr>
<tr><td colspan="3" align="center"><table><tr><td>
<input type="button" onClick="mystart();" value="开始"/></td><td>
<input type="button" onClick="mystop();" value="停止" /></td></tr></table></td></tr>
</table>
</div>
</body>
<script>
function myrandom()
{
var names = ["哈哈","花花","豆豆","坨坨","堆堆","哦哦","美羊羊","懒洋洋"];
var a1=Math.round(Math.random()*(names.length-1));
var b1=Math.round(Math.random()*(names.length-1));
var c1=Math.round(Math.random()*(names.length-1));
document.all["a"].innerHTML=names[a1];
document.all["b"].innerHTML=names[b1];
document.all["c"].innerHTML=names[c1];
}
function mystart()
{
timera=setInterval('myrandom()',20);
}
function mystop() {
clearInterval(timera);
}
</script>
3.文字轮播案例
<body onload="show()">
<!-- 展示文字 -->
<div id="da"></div>
</body>
<script type="text/javascript">
var i = 1;
function show(){
var str = "这是一个充满挑战与机遇的时代,请尽情拼搏吧!!!!";
var sa = str.substring(0,i);
document.getElementById("da").innerHTML = sa;
if(i == str.length){
i = 0;
}
i++;
setTimeout("show()",200);
}
</script>
4.图片轮换案例
<body>
<table width="360" border="0" cellspacing="0" cellpadding="0">
<tr>
<td style="height:190px;">
<div id="apDiv1">
<a onmouseover="changeImage('1.gif')" href="javascript:changeImage('1.gif')">1</a>
<a onmouseover="changeImage('2.gif')" href="javascript:changeImage('2.gif')">2</a>
<a onmouseover="changeImage('3.jpg')" href="javascript:changeImage('3.jpg')">3</a>
<a onmouseover="changeImage('4.jpg')" href="javascript:changeImage('4.jpg')">4</a>
<a onmouseover="changeImage('5.gif')" href="javascript:changeImage('5.gif')">5</a>
</div>
<img src="img/1.gif" alt="图片" id="p"/>
</td>
</tr>
</table>
</body>
<script type="text/javascript">
function changeImage(na){
var img = document.getElementById("p");
img.setAttribute("src","img/"+na);
}
</script>