隨筆 - 154  文章 - 60  trackbacks - 0
          <2008年3月>
          2425262728291
          2345678
          9101112131415
          16171819202122
          23242526272829
          303112345

          聲明:

          該blog是為了收集資料,認(rèn)識(shí)朋友,學(xué)習(xí)、提高技術(shù),所以本blog的內(nèi)容除非聲明,否則一律為轉(zhuǎn)載!!

          感謝那些公開自己技術(shù)成果的高人們!!!

          支持開源,尊重他人的勞動(dòng)!!

          常用鏈接

          留言簿(3)

          隨筆分類(148)

          隨筆檔案(143)

          收藏夾(2)

          其他

          學(xué)習(xí)(技術(shù))

          觀察思考(非技術(shù))

          搜索

          •  

          最新評(píng)論

          閱讀排行榜

          評(píng)論排行榜

          轉(zhuǎn)自:http://hi.baidu.com/lael80/blog/item/d0bd46df1941d31248540363.html

          javascript格式化數(shù)字,如 8888.85745 格式化成 8,888.86

          <html>
          <head>
          <title> New Document </title>
          </head>

          <body>
          <script language="JavaScript">
          <!--
          //lael 2005-11-09
          function formatnumber(fnumber,fdivide,fpoint,fround){

              var fnum = fnumber + '';
              var revalue="";

              if(fnum==null){
                  for(var i=0;i<fpoint;i++)revalue+="0";
                  return "0."+revalue;
              }
              fnum = fnum.replace(/^\s*|\s*$/g,'');
              if(fnum==""){
                  for(var i=0;i<fpoint;i++)revalue+="0";
                  return "0."+revalue;
              }

              fnum=fnum.replace(/,/g,"");

              if(fround){
                  var temp = "0.";
                  for(var i=0;i<fpoint;i++)temp+="0";
                  temp += "5";

                  fnum = Number(fnum) + Number(temp);
                  fnum += '';
              }

              var arrayf=fnum.split(".");

              if(fdivide){
                  if(arrayf[0].length>3){
                      while(arrayf[0].length>3){
                          revalue=","+arrayf[0].substring(arrayf[0].length-3,arrayf[0].length)+revalue;
                          arrayf[0]=arrayf[0].substring(0,arrayf[0].length-3);
                      }
                  }
              }
              revalue=arrayf[0]+revalue;

              if(arrayf.length==2&&fpoint!=0){
                  arrayf[1]=arrayf[1].substring(0,(arrayf[1].length<=fpoint)?arrayf[1].length:fpoint);

                  if(arrayf[1].length<fpoint)
                      for(var i=0;i<fpoint-arrayf[1].length;i++)arrayf[1]+="0";
                  revalue+="."+arrayf[1];
              }else if(arrayf.length==1&&fpoint!=0){
                  revalue+=".";
                  for(var i=0;i<fpoint;i++)revalue+="0";
              }

              return revalue;
          }
          //-->
          </script>

          <input name="text1" type="text" value="" onblur="this.value=formatnumber(this.value, true, 2, true)" />
          </body>
          </html>







          //日期比較
          function datecompare(date1, date2){
          var d1 = new Date(date1.replace(/\-/g, "\/"));
          var d2 = new Date(date2.replace(/\-/g, "\/"));

          var flag = true;

          if(isNaN(d1) || isNaN(d2))flag = false;//不是日期

          if(flag &&
          d1.getFullYear() > d2.getFullYear()){
          flag = false;
          }
          if(flag &&
          d1.getFullYear() == d2.getFullYear() &&
          d1.getMonth() > d2.getMonth()){
          flag = false;
          }
          if(flag &&
          d1.getFullYear() == d2.getFullYear() &&
          d1.getMonth() == d2.getMonth() &&
          d1.getDate() > d2.getDate()){
          flag = false;
          }
          return flag;
          }



          //cookie


          function getcookievalue(sname){
          var svalue="";
          var sname=sname+"=";
          if(document.cookie.length>0){
          offset=document.cookie.indexOf(sname);
          if(offset!=-1){
          offset+=sname.length;
          end=document.cookie.indexOf(";",offset);
          if(end==-1)end=document.cookie.length;
          svalue=unescape(document.cookie.substring(offset,end))
          }
          }
          return svalue;
          }

          function setcookievalue(sname,svalue){
          var expire="";
          expire=new Date((new Date()).getTime()+31536000);
          expire="; expires="+expire.toGMTString();
          document.cookie=sname+"="+escape(svalue)+expire;
          }



          光標(biāo)處插入或修改文字

          function storeCaret(_obj1){
              if(_obj1.createTextRange)
                  _obj1.caretPos = document.selection.createRange().duplicate();  
          }

          function insertAtCaret() {
              var _obj1 = document.getElementById("textarea1");
                 
              var _text = "[b]";
             
              _obj1.focus();
              storeCaret(_obj1);
             
              if(_obj1.createTextRange && _obj1.caretPos){
                  var caretPos = _obj1.caretPos;
                  caretPos.text = caretPos.text.charAt(caretPos.text.length - 1) == ' ' ?_text + ' ' : _text;     
              }else _obj1.value = _text;
          }






          JS圖片動(dòng)畫效果
          效果:http://www.carsclub.com.cn/

          <style>
          #flash_img {
              filter: revealtrans(duration=2.0,transition=12); width: 100%;
          }
          </style>

          <table border="0" align="right" cellpadding="0" cellspacing="0">
                              <tr>
                                <td class="focus-ctl-nows" id="flash_show_ctl_0" onClick="showImage(0);">1</td>

                                <td class="focus-ctl" id="flash_show_ctl_1" onClick="showImage(1);">2</td>
                                <td class="focus-ctl" id="flash_show_ctl_2" onClick="showImage(2);">3</td>
                                <td class="focus-ctl" id="flash_show_ctl_3" onClick="showImage(3);">4</td>
                                <td class="focus-ctl" id="flash_show_ctl_4" onClick="showImage(4);">5</td>
                                <td>&nbsp;</td>
                              </tr>
                            </table>

          <div id="flash_img" style="width:334px; height:167px;"></div>

          <script language="javascript">
          <!--
          ////////////////begin
          var showImageIndex = -1;
          var imageTimer = null;
          function showImage(imageIndex)
          {
              var flash_img_div = document.getElementById("flash_img");
             
              if(imageIndex>=fImgs.length){
                  imageIndex = 0;
              }
             
              if(!fImgs[imageIndex] || imageIndex==showImageIndex)return false;   
             
              var imgId = "__fImg"+imageIndex;
              flash_img_div.filters && flash_img_div.filters[0].Apply();
              for(var i=0; i<flash_img_div.childNodes.length; i++){
                  flash_img_div.removeChild(flash_img_div.childNodes[i]);
              }
              for(var i=0; i<fImgs.length;i++){
                  if(i == imageIndex)continue;
                  document.getElementById("flash_show_ctl_" + i).className = "focus-ctl";   
              }
              document.getElementById("flash_show_ctl_" + imageIndex).className = "focus-ctl-nows";
              var pos = fImgs[imageIndex].img.lastIndexOf(".");
              if( fImgs[imageIndex].img.substr(pos+1).substr(0,3).toLowerCase()=="swf" ){
                  flash_img_div.innerHTML += '\
                      <object classid="clsid:D27CDB6E-AE6D-11cf-96B8-444553540000" codebase="http://download.macromedia.com/pub/shockwave/cabs/flash/swflash.cab#version=7,0,19,0" width="334" height="167" id="'+imgId+'">\
                          <param name="movie" value="'+fImgs[imageIndex].img+'" />\
                          <param name="quality" value="high" />\
                          <param name="wmode" value="transparent">\
                          <param name="scale" value="exactfit">\
                          <embed src="'+fImgs[imageIndex].img+'" quality="high" pluginspage="http://www.macromedia.com/go/getflashplayer" type="application/x-shockwave-flash" width="334" height="167"></embed>\
                      </object>';
              }else{
                  var img = new Image();
                  img.border = "0";
                  img.src = fImgs[imageIndex].img;
                  img.width = "334";
                  img.height = "167";
                  var a = document.createElement("a");
                  a.href = fImgs[imageIndex].href;
                  a.title = fImgs[imageIndex].title;
                  a.target = "_blank";
                  a.id = imgId;
                  a.appendChild(img);
                  flash_img_div.appendChild(a);
              }
              flash_img_div.filters && flash_img_div.filters[0].Play();
              showImageIndex = imageIndex;
             
              return true;
          }
          function imagePlay()
          {
              if(imageTimer) return;
              if(showImageIndex>=fImgs.length){
                  showImageIndex = -1;
              }
              showImage(showImageIndex+1);
              imageTimer = setInterval(function(){
                              var stat = showImage(showImageIndex+1);
                              if(!stat){
                                  imageStop();
                              }   
                          },8000);
          }
          function imageStop(){
              if(imageTimer)clearInterval(imageTimer);
              imageTimer = null;
          }
          function showNextImage(){
              showImage(showImageIndex+1);
          }
          function showPrevImage(){
              showImage(showImageIndex-1);
          }

          var fImgs = new Array();
          fImgs[0] = {title:"",img:"upload/images/subject/2007-02-06/1174915891_outline.jpg",href:"news.php?id=220"};
          fImgs[1] = {title:"",img:"upload/images/subject/2007-02-06/1175244094_outline.jpg",href:"news.php?id=212"};
          fImgs[2] = {title:"",img:"upload/images/subject/2007-02-06/1177150583_outline.jpg",href:"news.php?id=219"};
          fImgs[3] = {title:"",img:"upload/images/subject/2007-02-06/1175897263_outline.jpg",href:"news.php?id=217"};
          fImgs[4] = {title:"",img:"upload/images/subject/2007-02-06/1177509461_outline.jpg",href:"news.php?id=213"};
          ////////////////end

          window.document.body.onload = new function(){
              imagePlay();//焦點(diǎn)圖文
          }
          //-->
          </script>

          posted on 2008-03-20 16:45 lk 閱讀(2324) 評(píng)論(0)  編輯  收藏 所屬分類: ajax&js
          主站蜘蛛池模板: 中牟县| 天台县| 富锦市| 潍坊市| 同心县| 庐江县| 江陵县| 安陆市| 康平县| 大庆市| 新晃| 聂荣县| 新田县| 保靖县| 宁化县| 大城县| 岳阳县| 巴林右旗| 怀安县| 宝丰县| 承德县| 蛟河市| 金沙县| 镇原县| 图们市| 平度市| 措美县| 黔东| 东丽区| 筠连县| 双流县| 台江县| 大英县| 盈江县| 平南县| 章丘市| 沧州市| 江川县| 防城港市| 罗山县| 苗栗市|