javascript实践一些功能

 几秒后跳转功能:


<html>
<head><title></title>
<script language='javascript' type='text/javascript'>
     var secs =5; //倒计时的秒数
     var URL ;
     function Load(url){
        URL =url;
        for(var i=secs;i>=0;i--)
       {
         window.setTimeout('doUpdate(' + i + ')', (secs-i) * 1000);
       
       }
    }
   
    function doUpdate(num)
    {
     document.getElementById('ShowDiv').innerHTML = '将在'+num+'秒后自动跳转到 sohu' ;
     if(num == 0) { window.location=URL;  }
    }
  </script>


</head>
<body>
<div id="ShowDiv"></div>
<script language="javascript">
Load("http://www.sohu.com");
</script>
</body>
</html>

 

动态生成按钮并动态生成8位随机数

<script language="javascript">
var i=0;
var timer1;

function doPrint() {    
 //bdhtml=window.document.body.innerHTML;   
 //sprnstr="<!--startprint-->";   
 //eprnstr="<!--endprint-->";   
 //prnhtml=bdhtml.substr(bdhtml.indexOf(sprnstr)+17);   
 //prnhtml=prnhtml.substring(0,prnhtml.indexOf(eprnstr));   
 //window.document.body.innerHTML=prnhtml;   
 window.print();
// window.document.body.innerHTML=bdhtml;
 
 
}

function init(){    
 
  x=Math.random();  
  x=Math.floor(x*100000000);
  if(x<9999999){  
      init();  
  }else{
 i++;
    document.all.show.innerText=x;
    if(i==20){
     var par=document.getElementById("mybutton");
     var son_tr=document.createElement("TR");
     var son_td=document.createElement("TD");
     //列属性
     son_td.colSpan="4";
     son_td.setAttribute("align","center");
     son_td.setAttribute("className","b_table_db1");
     //生成密码属性
  var input_type=document.createElement("INPUT");
  input_type.type="button";
  input_type.name="createCode";
  input_type.value="确认密码";
  input_type.οnclick=save_onclick;
  input_type.setAttribute("className","button");
  input_type.onFocus="this.blur();";
  input_type.οnmοuseοver='this.className="buttonY";';
  input_type.οnmοuseοut='this.className="button"';
  //打印属性
  var input_type2=document.createElement("INPUT");
  input_type2.type="button";
  input_type2.name="printButton";
  input_type2.value="打印";
  input_type2.οnclick=doPrint;
  input_type2.setAttribute("className","button");
  input_type2.onFocus="this.blur();";
  input_type2.οnmοuseοver='this.className="buttonY";';
  input_type2.οnmοuseοut='this.className="button"';
  
  
  son_td.appendChild(input_type);
  son_td.appendChild(input_type2);
  son_tr.appendChild(son_td);
  par.appendChild(son_tr);
    }  
   
 if(i<20){
  timer1=setTimeout("init()",50);
 }
 
}

}
//确认密码
function save_onclick(){
 alert("确认密码");
}
</script>
<html>
<head><title></title></head>
<body>
<table>
<tr>
<td id="show"></td>
</tr>
<tbody id="mybutton"></tbody>
</table>
</body>
<script language="javascript">
init();
</script>
</html>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值