一二三区免费观看|av无码字幕av|亚洲AV综合色区无码一区|五月激情网婷婷激情|久久久久久久久久久久久大色天下|国产97av在线|四虎一区在线观看|96人人操_人人|九九九日本精品免费观看|伊人久久激情

jQuery實現的拖動調整表格單元格的大小代碼實例

時間:2024-08-14 23:59:11 jQuery 我要投稿
  • 相關推薦

jQuery實現的拖動調整表格單元格的大小代碼實例

  jQuery實現的拖動調整表格td單元格的大小:

  在實際應用中,可能有這樣的需求,那就是需要調整td單元格的大小。

  也許是為了便于觀察,也許是其他原因,反正這樣的需求是有的,下面就分享一段能夠實現此功能的代碼。

  代碼實例如下:

  復制代碼 代碼如下:

  table {

  border-collapse: collapse;

  }

  td {

  text-align: center;

  }

  (function ($){

  $.fn.tableresize = function () {

  var _document = $("body");

  $(this).each(function () {

  if (!$.tableresize) {

  $.tableresize = {};

  }

  var _table = $(this);

  //設定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();

  //設定臨時變量存放對象

  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
名字
年紀
地址
電話

            
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實現的拖動調整表格單元格的大小代碼實例】相關文章:

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

關jQuery彈出窗口簡單實現代碼-javascript編程06-07

jquery提交按鈕的代碼07-28

關于jQuery實現高亮顯示的方法介紹08-20

JavaScript實現網頁刷新代碼段08-07

將php實現過濾UBB代碼09-11

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

防盜鏈接ASP函數實現代碼01-23

常用排序算法之JavaScript實現代碼段06-04

關于jquery簡單圖片切換顯示效果實現方法介紹10-01