1.轮播图效果:
1 <html> 2 <head> 3 <title></title> 4 <script> 5 var b = 1; 6 function showImg(type){ 7 document.getElementById("imgDiv").innerHTML='<img src="img/'+b+'.jpg">';//修改div的内容 8 if(type == 'shang'){//点击上一页b-- 9 b--; 10 if(b == 0){//如果是第一张 修改为最后一张 11 b = 6; 12 } 13 }else{//点击上一张 b自增 14 b++; 15 if(b==7){//如果是最后一张 修改为第一张 16 b = 1; 17 } 18 } 19 } 20 </script> 21 </head> 22 <body> 23 <div id="imgDiv"> 24 <img src="img/1.jpg"> 25 </div> 26 </body> 27 </html>
2.回文数:求1~9999之间的整数,判断是否文回文数,如果是则输出并且输出这个数的位数。
1 <html> 2 <head> 3 <title></title> 4 <script> 5 function one(){ 6 for(var i = 1; i<10000;i++){ 7 var num = i + ""; //转成字符串 8 var num1 = ""; 9 //"1234" => ["1","2","3","4"] => ["4","3","2","1"] 10 for(var j = num.length-1; j>=0; j--){ 11 num1 = num1 + num[j]; 12 } 13 if(+num == +num1){ 14 document.write(num + "是回文数" + num.length + "<br>"); 15 } 16 } 17 } 18 </script> 19 </head> 20 <body> 21 <input type="button" value="开始计算" onClick="one()"> 22 </body> 23 </html>
3.5个评委打分 去掉一个最高分 去掉一个最低分 最后得分
<html> <head> <title></title> <script> function two(){ var sum = 0, max = 0, min = 0; for(var i = 0; i<5;i++){ if(i == 0){ var num = prompt("输入成绩"); max = num; min = num; }else{ var num = prompt("输入成绩"); if(max < +num){ max = +num; } if(min > +num){ min = +num; } } sum = sum + +num; } document.write(sum + "<br>"); document.write(max + "<br>"); document.write(min + "<br>"); document.write(sum - max - min); </script> </head> <body> <input type="button" value="开始打分" onClick="two()"> </body> </html>
4.使用getElementBy...改变属性值:
<html> <head> <title></title> <script> function aa(obj){ var objdiv = document.getElementById("bb"); objdiv.setAttribute("class","big"); } </script> </head> <body> <button onClick="aa(this)">变大</button> </body> </html>