一区二区三区在线-一区二区三区亚洲视频-一区二区三区亚洲-一区二区三区午夜-一区二区三区四区在线视频-一区二区三区四区在线免费观看

服務(wù)器之家:專注于服務(wù)器技術(shù)及軟件下載分享
分類導(dǎo)航

node.js|vue.js|jquery|angularjs|React|json|js教程|

服務(wù)器之家 - 編程語言 - JavaScript - 使表格的標題列可左右拉伸jquery插件封裝

使表格的標題列可左右拉伸jquery插件封裝

2021-04-24 18:22 JavaScript

這篇文章主要介紹了使表格的標題列可左右拉伸jquery插件封裝,需要的朋友可以參考下

插件名稱命名為:jquery.tableresize.js,代碼如下:

 

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

/*
Writen by mlcactus, 2014-11-24
這是我封裝的一個jquery插件,能夠使table的各列可以左右拉伸,從而使寬度變小或變大
用法:
單個table:$("#table_id").tableresize();   
頁面所有table:$("table").tableresize();
*/
(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è)定臨時變量存放對象
            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 < bottom && (leftside || rightside)) {
                    _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);  

 

頁面代碼為:

 

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

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title></title>
    <style type="text/css" >
        td{ text-align:center;}
    </style>
    <script type="text/javascript" src="script/jquery-1.10.2.js"></script>
    <script type="text/javascript" src="script/jquery.tableresize.js"></script>
    <script type="text/javascript">
        $(document).ready(function () {
            //使兩張table同時支持左右拉伸
            $("table").tableresize();
        });
    </script>
</head>
<body>
    表格1<br/>
    <table cellspacing="0" border="1" style="border-collapse:collapse;" rules="all">
        <tbody><tr>
            <td style="width:200px;">ID</td><td style="width:200px;">名字</td><td style="width:200px;">年紀</td><td style="width:200px;">地址</td><td style="width:200px;">電話</td>
        </tr><tr>
            <td>22</td><td>Name:44</td><td>Age:23</td><td>Address:47</td><td>Phone:15</td>
        </tr><tr>
            <td>28</td><td>Name:42</td><td>Age:68</td><td>Address:30</td><td>Phone:50</td>
        </tr><tr>
            <td>29</td><td>Name:63</td><td>Age:48</td><td>Address:90</td><td>Phone:76</td>
        </tr>
    </tbody>
    </table>
    <br/>表格2<br/>
    <table cellspacing="0" border="1" style="border-collapse:collapse;" rules="all">
        <tbody><tr>
            <td style="width:200px;">ID</td><td style="width:200px;">名字</td><td style="width:200px;">年紀</td><td style="width:200px;">地址</td><td style="width:200px;">電話</td>
        </tr><tr>
            <td>22</td><td>Name:44</td><td>Age:23</td><td>Address:47</td><td>Phone:15</td>
        </tr><tr>
            <td>28</td><td>Name:42</td><td>Age:68</td><td>Address:30</td><td>Phone:50</td>
        </tr>
    </tbody></table>
</body>
</html>

延伸 · 閱讀

精彩推薦
主站蜘蛛池模板: 成人福利在线播放 | 成人小视频在线观看 | 九九九九九九精品免费 | 男人的天堂欧美 | caoporn人人| 91国语自产拍在线观看 | 免费av在线视频 | 欧美成人香蕉在线观看 | 黄网久久 | 肉文高h调教 | 欧美聚众性派对hdsex | 青青草人人 | 国产情侣视频观看 | 国产1区2区三区不卡 | 亚洲精品国产成人7777 | 天天欲色成人综合网站 | 国产三级精品久久三级国专区 | 免费国产网站 | 亚洲成人99 | 人人干国产 | 99热这里只有精品在线 | 欧美不卡一区二区三区 | 亚洲午夜视频 | 国产精品色图 | 国产成人精品一区二区阿娇陈冠希 | 99视频有精品视频免费观看 | 久久中文字幕无线观看 | 涩涩漫画软件 | 很黄的孕妇a级黄毛片 | 国产色网址 | 五月天在线视频观看 | 精品一区二区三区五区六区七区 | 1919gogo女厕盗摄 | 亚洲国产精品久久无套麻豆 | 午夜小视频网站 | 第一次做m被调教经历 | 亚洲天堂导航 | 嗯好爽视频 | 沉沦艳妇杨幂肉体小说 | 秋霞一级黄色片 | 日日爽日日操 |