jQuery實(shí)現(xiàn)的拖動(dòng)調(diào)整表格單元格的大小代碼實(shí)例

    時(shí)間:2024-08-14 23:59:11 jQuery 我要投稿
    • 相關(guān)推薦

    jQuery實(shí)現(xiàn)的拖動(dòng)調(diào)整表格單元格的大小代碼實(shí)例

      jQuery實(shí)現(xiàn)的拖動(dòng)調(diào)整表格td單元格的大小:

      在實(shí)際應(yīng)用中,可能有這樣的需求,那就是需要調(diào)整td單元格的大小。

      也許是為了便于觀察,也許是其他原因,反正這樣的需求是有的,下面就分享一段能夠?qū)崿F(xiàn)此功能的代碼。

      代碼實(shí)例如下:

      復(fù)制代碼 代碼如下:

      table {

      border-collapse: collapse;

      }

      td {

      text-align: center;

      }

      (function ($){

      $.fn.tableresize = function () {

      var _document = $("body");

      $(this).each(function () {

      if (!$.tableresize) {

      $.tableresize = {};

      }

      var _table = $(this);

      //設(shè)定ID

      var id = _table.attr("id") || "tableresize_" + (Math.random() * 100000).toFixed(0).toString();

      var tr = _table.find("tr").first(), ths = tr.children(), _firstth = ths.first();

      //設(shè)定臨時(shí)變量存放對(duì)象

      var cobjs = $.tableresize[id] = {};

      cobjs._currentObj = null, cobjs._currentLeft = null;

      ths.mousemove(function (e) {

      var _this = $(this);

      var left = _this.offset().left,

      top = _this.offset().top,

      width = _this.width(),

      height = _this.height(),

      right = left + width,

      bottom = top + height,

      clientX = e.clientX,

      clientY = e.clientY;

      var leftside = !_firstth.is(_this) && Math.abs(left - clientX) <= 5,

      rightside = Math.abs(right - clientX) <= 5;

      if (cobjs._currentLeft||clientY>top&&clientY

      _document.css("cursor", "e-resize");

      if (!cobjs._currentLeft) {

      if (leftside) {

      cobjs._currentObj = _this.prev();

      }

      else {

      cobjs._currentObj = _this;

      }

      }

      }

      else {

      cobjs._currentObj = null;

      }

      });

      ths.mouseout(function (e) {

      if (!cobjs._currentLeft) {

      cobjs._currentObj = null;

      _document.css("cursor", "auto");

      }

      });

      _document.mousedown(function (e) {

      if (cobjs._currentObj) {

      cobjs._currentLeft = e.clientX;

      }

      else {

      cobjs._currentLeft = null;

      }

      });

      _document.mouseup(function (e) {

      if (cobjs._currentLeft) {

      cobjs._currentObj.width(cobjs._currentObj.width() + (e.clientX - cobjs._currentLeft));

      }

      cobjs._currentObj = null;

      cobjs._currentLeft = null;

      _document.css("cursor", "auto");

      });

      });

      };

      })(jQuery);

      $(document).ready(function () {

      $("table").tableresize();

      });


                

                

                
    ID
    名字
    年紀(jì)
    地址
    電話

                
    22
    Name:44
    Age:23
    Address:47
    Phone:15

                
    28
    Name:42
    Age:68
    Address:30
    Phone:50

                
    29
    Name:63
    Age:48
    Address:90
    Phone:76

    【jQuery實(shí)現(xiàn)的拖動(dòng)調(diào)整表格單元格的大小代碼實(shí)例】相關(guān)文章:

    基于jQuery的固定表格頭部的代碼08-30

    關(guān)jQuery彈出窗口簡(jiǎn)單實(shí)現(xiàn)代碼-javascript編程06-07

    jquery提交按鈕的代碼07-28

    關(guān)于jQuery實(shí)現(xiàn)高亮顯示的方法介紹08-20

    JavaScript實(shí)現(xiàn)網(wǎng)頁(yè)刷新代碼段08-07

    將php實(shí)現(xiàn)過(guò)濾UBB代碼09-11

    excel怎樣隱藏表格單元格08-05

    防盜鏈接ASP函數(shù)實(shí)現(xiàn)代碼01-23

    常用排序算法之JavaScript實(shí)現(xiàn)代碼段06-04

    關(guān)于jquery簡(jiǎn)單圖片切換顯示效果實(shí)現(xiàn)方法介紹10-01

    91久久大香伊蕉在人线_国产综合色产在线观看_欧美亚洲人成网站在线观看_亚洲第一无码精品立川理惠

      亚洲日本337视频大全 | 中文字幕视频综合网 | 亚洲欧美国产另类视频 | 日本免费高清一区二区三区最新 | 日韩AV午夜在线观看不卡 | 日韩欧美国产精品91 |