诱红楼封面大图:常用js

来源:百度文库 编辑:九乡新闻网 时间:2024/05/03 05:37:46

1.  js实现浮点数位数的保留

方法1:  /**
  *v表示要转换的值
  *e表示要保留的位数
  */
  function round(v,e){
   var t=1;
   for(;e>0;t*=10,e--);
   for(;e<0;t/=10,e++);
   return Math.round(v*t)/t;
  }使用方法:value = round(value,2);//保留2位小数,并且可以格式化数字,在数字过大时不会出现科学计数法。方法2:value=parseFloat(value).toFixed(2).toString();//保留2位小数,并且可以格式化数字,在数字过大时不会出现科学计数法。

 2.  js日历控件的使用

引进js文件:使用:1) 使用默认格式:及yyyy-MM-dd2) 指定格式:如:yyyy-MM-dd或yyyy-MM或yyyy-MM-dd HH:mm:ss说明:skin:'whyGreen'设定控件的样式class="Wdate" 设定输入框到的样式注:使用的时候需要日历控件的js文件的支持。 

 2.  关闭子窗口刷新父窗口

父窗口写法:      window.open("...");void 0;子窗口写法:      执行完其他的操作(比如:提交表单form.submit,或window.location.href=""),      执行:window.opener.location=window.opener.location; this.close();

 3.  将秒转换成小时分钟秒的js

function formatSeconds(value) {  
   var theTime = Number(value);  
   var theTime1 = 0;  
   var theTime2 = 0;  
   //alert(theTime);  
   if(theTime > 60) {  
      theTime1 = Number(theTime/60);  
      theTime = Number(theTime%60);  
      //alert(theTime1+"-"+theTime);  
      if(theTime1 > 60) {  
         theTime2 = Number(theTime1/60);  
         theTime1 = Number(theTime%60);  
      }  
   }  
   var result = ""+theTime+"s";  
   if(theTime1 > 0) {  
      result = ""+parseInt(theTime1)+"m"+result;  
   }  
   if(theTime2 > 0) {  
      result = ""+parseInt(theTime2)+"h"+result;  
   }  
   return result;  
  }