郑桂良ID:phker
108次访问,排名2万外好友0人,关注者0
phker的文章
原创 4 篇
翻译 0 篇
转载 0 篇
评论 2 篇
最近评论
phker:已经替换过了!
目前的这个是最新的!
使用了比较好的代码!
如果有人想要完整的代码请联系QQ273082449
phker:不好意思这个不是最佳的中文处理方法!是我转载的
最佳的方法我待会回家贴上!
文章分类
    收藏
      相册
      存档
      软件项目交易
      订阅我的博客
      XML聚合  FeedSky
      订阅到鲜果
      订阅到Google
      订阅到抓虾
      订阅到BlogLines
      订阅到Yahoo
      订阅到GouGou
      订阅到飞鸽
      订阅到Rojo
      订阅到newsgator
      订阅到netvibes

      原创 功能很全的JavaScript 处理web表格收藏

       | 旧一篇: javaScript表格宽度拖拉效果

       
      <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
      <title>Power Table</title>
      <style>
      body
      {
       FONT-SIZE
      : 9pt; PADDING-RIGHT: 0px; PADDING-LEFT: 0px; PADDING-BOTTOM: 0px; PADDING-TOP: 0px;
      }

      input 
      {
       FONT-SIZE
      : 9pt; height: 15pt; width:50px; cursor: default;
      }

      table
      {
       font-size
      : 9pt;
       word-break
      :break-all;
       cursor
      : default;
       BORDER
      : black 1px solid;
       background-color
      :#eeeecc;
       border-collapse
      :collapse;
       border-Color
      :#999999;
       align
      :center;
      }

      </style>
      <script language="JavaScript1.2">
      /*
       This following code are designed and writen by Windy_sk <windy_sk@126.com>
       You can use it freely, but u must held all the copyright items!
      */

      var Main_Tab = null;
      var cur_row = null;
      var cur_col = null;
      var cur_cell = null;
      var Org_con = "";
      var sort_col = null;
      var show_col = false;
      var charMode = 1;
      var act_bgc = "#BEC5DE";
      var act_fc = "black";
      var cur_bgc = "#ccffcc";
      var cur_fc = "black";
      function init(){
       cur_row   
      = null;
       cur_col   
      = null;
       cur_cell  
      = null;
       sort_col  
      = null;
       Main_Tab   
      = PowerTable;
       read_def(Main_Tab)
       Main_Tab.onmouseover 
      = overIt;
       Main_Tab.onmouseout 
      = outIt;
       Main_Tab.onclick 
      = clickIt;
       Main_Tab.ondblclick 
      = dblclickIt;
       Org_con   
      = Main_Tab.outerHTML;
       
       arrow 
      = document.createElement("SPAN");
       arrow.style.cssText  
      = "PADDING-RIGHT: 0px; MARGIN-TOP: -3px; PADDING-LEFT: 0px; FONT-SIZE: 10px; MARGIN-BOTTOM: 2px; PADDING-BOTTOM: 2px; OVERFLOW: hidden; WIDTH: 10px; COLOR: blue; PADDING-TOP: 0px; FONT-FAMILY: webdings; HEIGHT: 11px";
      }

      function window.onload(){
       init();
       drag 
      = document.createElement("DIV");
       drag.innerHTML  
      = "";
       drag.style.textAlign  
      = "center";
       drag.style.position  
      = "absolute";
       drag.style.cursor  
      = "hand";
       drag.style.border  
      = "1 solid black";
       drag.style.display  
      = "none";
       drag.style.zIndex  
      = "999";
       
       document.body.insertBefore(drag);
       setInterval(
      "judge_move()",100);
       setInterval(
      "showContent.value=Main_Tab.innerHTML;monitor.value='cur_row: '+cur_row+'; cur_col: '+cur_col + '; sort_col: ' +sort_col",1000);
       sel_Mode.selectedIndex
      =charMode;
      }

      function judge_move(){
       move[
      0].disabled=(cur_row == null || cur_row<=1);
       move[
      1].disabled=(cur_row == null || cur_row==Main_Tab.rows.length-1 || cur_row == 0);
       move[
      2].disabled=(cur_col == null || cur_col==0);
       move[
      3].disabled=(cur_col == null || cur_col==Main_Tab.rows[0].cells.length-1);
      }

      document.onselectstart 
      = function(){return false;}
      document.onmouseup 
      = drag_end;
      function clear_color(){
       the_table
      =Main_Tab;
       
      if(cur_col!=null){
        
      for(i=0;i<the_table.rows.length;i++){
         
      with(the_table.rows[i].cells[cur_col]){
          style.backgroundColor
      =oBgc;
          style.color
      =oFc;
         }

        }

       }

       
      if(cur_row!=null){
        
      for(i=0;i<the_table.rows[cur_row].cells.length;i++){
         
      with(the_table.rows[cur_row].cells[i]){
          style.backgroundColor
      =oBgc;
          style.color
      =oFc;
         }

        }

       }

       
      if(cur_cell!=null){
        cur_cell.children[
      0].contentEditable = false;
        
      with(cur_cell.children[0].runtimeStyle){
         borderLeft
      =borderTop="";
         borderRight
      =borderBottom="";
         backgroundColor
      ="";
         paddingLeft
      ="";
         textAlign
      ="";
        }

       }

      }

      function document.onclick(){
       window.status 
      = "";
       clear_color();
       cur_row  
      = null;
       cur_col  
      = null;
       cur_cell 
      = null;
      }

      function read_def(the_table){
       
      for(var i=0;i<the_table.rows.length;i++){
        
      for(var j=0;j<the_table.rows[i].cells.length;j++){
         
      with(the_table.rows[i]){
          cells[j].oBgc 
      = cells[j].currentStyle.backgroundColor;
          cells[j].oFc  
      = cells[j].currentStyle.color;
          
      if(i==0){
           cells[j].onmousedown 
      = drag_start;
           cells[j].onmouseup 
      = drag_end;
          }

         }

        }

       }

      }

      function get_Pos(the_obj){
       the_top 
      = the_obj.offsetTop - document.body.scrollTop; 
       the_left 
      = the_obj.offsetLeft - document.body.scrollLeft; 
       
      while(the_obj=the_obj.offsetParent)
        the_top 
      += the_obj.offsetTop; 
        the_left 
      += the_obj.offsetLeft; 
       }

       
      this.top = the_top; 
       
      this.left = the_left; 
      }

      function get_Element(the_ele,the_tag){
       the_tag 
      = the_tag.toLowerCase();
       
      if(the_ele.tagName.toLowerCase()==the_tag)return the_ele;
       
      while(the_ele=the_ele.offsetParent){
        
      if(the_ele.tagName.toLowerCase()==the_tag)return the_ele;
       }

       
      return(null);
      }

      var dragStart  = false;
      var dragColStart = null;
      var dragColEnd  = null;
      function drag_start(){
       
      var the_td = get_Element(event.srcElement,"td");
       
      if(the_td==nullreturn;
       dragStart 
      = true;
       dragColStart 
      = the_td.cellIndex;
       drag.style.width 
      = the_td.offsetWidth;
       drag.style.height 
      = the_td.offsetHeight;
       
      function document.onmousemove(){
        drag.style.display 
      = "";
        drag.style.top  
      = event.y + document.body.scrollTop - drag.offsetHeight/2;
        drag.style.left  
      = event.x + document.body.scrollLeft - drag.offsetWidth/2;
        
      for(var i=0;i<Main_Tab.rows[0].cells.length;i++){
         
      var the_cell = new get_Pos(Main_Tab.rows[0].cells[i]);
         
      with(Main_Tab.rows[0].cells[i]){
          
      if((event.y>the_cell.top+parseInt(document.body.currentStyle.marginTop)-offsetHeight/2 && event.y<the_cell.top+offsetHeight/2+parseInt(document.body.currentStyle.marginTop)) && (event.x>the_cell.left+parseInt(document.body.currentStyle.marginLeft) && event.x<the_cell.left+offsetWidth+parseInt(document.body.currentStyle.marginLeft))){
           runtimeStyle.backgroundColor
      =act_bgc;
           dragColEnd
      =cellIndex;
          }
      else{
           runtimeStyle.backgroundColor
      ="";
          }

         }

        }

        
      var the_line = new get_Pos(Main_Tab.rows[0]);
        
      if(!(event.y>the_line.top+parseInt(document.body.currentStyle.marginTop)-Main_Tab.rows[0].offsetHeight/2 && event.y<the_line.top+parseInt(document.body.currentStyle.marginTop)+Main_Tab.rows[0].offsetHeight/2)) dragColEnd=null;
       }

       drag.innerHTML 
      = the_td.innerHTML;
       drag.style.backgroundColor 
      = the_td.oBgc;
       drag.style.color 
      = the_td.oFc;
      }

      function drag_end(){
       dragStart 
      = false;
       drag.style.display
      ="none";
       drag.innerHTML 
      = "";
       drag.style.width 
      = 0;
       drag.style.height 
      = 0;
       
      for(var i=0;i<Main_Tab.rows[0].cells.length;i++){
        Main_Tab.rows[
      0].cells[i].runtimeStyle.backgroundColor="";
       }

       
      if(dragColStart!=null && dragColEnd!=null && dragColStart!=dragColEnd){
        change_col(Main_Tab,dragColStart,dragColEnd);
        
      if(dragColStart==sort_col)sort_col=dragColEnd;
        
      else if(dragColEnd==sort_col)sort_col=dragColStart;
        doc