玄铁剑

成功的途径:抄,创造,研究,发明...
posts - 128, comments - 42, trackbacks - 0, articles - 174

常用javascript腳本

Posted on 2007-09-04 08:28 玄铁剑 阅读(231) 评论(0)  编辑 收藏 引用 所属分类: asp.net

 
  
        function getSelectedItem()
        {
           var list = document.getElementById("radiobuttonlist");
           var options = list.getElementsByTagName("input");
           var str = "";
           for( x = 0; x < options.length; ++x )
           {
             if( options[x].type == "radio" && options[x].checked )
             {
               str = options[x].value;
               break;
             }
           }
           return str;
        }  
       
               String.prototype.trim = function()
       {
          return this.replace(/^\s+|\s+$/g,"");
       }
      
       String.prototype.ltrim = function()
       {
          return this.replace(/^\s+/,"");
       }
      
       String.prototype.rtrim = function()
       {
          return this.replace(/\s+$/,"");
       }
      
       function getleft(str,count)
       {
          var sl=str;
          sl = sl.substring(0,count);
          return sl;
       }

       function getright(str,count)
       {
          var sr=str;
          sr = sr.substring(sr.length-count,sr.length);
          return sr;
       }
      
       function delay(numberMillis)
       {
          var now = new Date();
          var exitTime = now.getTime()+numberMillis;
          while(true)
          {
             now = new Date();
             if(now.getTime() > exitTime)
                return;
          }
       }       
      
        function setCookie(key,value)
        {
           document.cookie = key+"="+escape(value);  
        }      
      
        function readcookie(name)
        {
            var mycookie = document.cookie;
            var start1 = mycookie.indexOf(name + "=");
            if (start1== -1)
              return "";
            else
            {
                start=mycookie.indexOf("=",start1)+1;
                var end = mycookie.indexOf(";",start);
                 if (end==-1)
                 {
                     end=mycookie.length;
                 }
                 var value=unescape(mycookie.substring(start,end));
                 if (value==null)
                 {
                    return "";
                 }
                 else
                 {
                    return value;
                 }
             }
       } 
         
         //正則表達[數字/字母/減號]
          str=str.replace(/[^\d\w\-]+$/,"");
          str=str.replace(/[^\d\w\-]/g,"");               
          str = str.trim().replace(/\040/g,"");

          //Gridview/Table read
          var tb = document.getElementById("ctl00_ContentPlaceHolder1_control");
          if (tb.rows.length>=1)
          {
             var str = tb.rows[1].cells[2].innerHTML;
          }   



实现局部打印
<style media="print">
         .Noprint 
{ DISPLAY: none }
         .PageNext
{ PAGE-BREAK-AFTER: always }
   </style>
第一个在不需要打印的标签上添加(子标签也将不被打印),第二个在需要换行的标签处添加(该标签所表示的内容将在当前打印的一页内)

接下来通过调用最基本的js语句
window.print()
只有注册用户登录后才能发表评论。