table切换jquery插件 jQuery插件写法模板 流程

本文介绍了如何通过$.extend()扩展jQuery的功能,并演示了如何利用$.fn为jQuery添加新的方法实现表格内容的动态切换。通过具体实例展示了jQuery的灵活性及其实现网页交互的能力。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

 

 

 

  1. 通过$.extend()来扩展jQuery
  2. 通过$.fn 向jQuery添加新的方法
  3. 通过$.widget()应用jQuery UI的部件工厂方式创建

 

 

  1. 通过$.extend()来扩展jQuery
$.extend({
    sayHello: function(name) {
        console.log('Hello,' + (name ? name : 'Dude') + '!');
    }
})
$.sayHello(); //调用
$.sayHello('Wayou'); 

2 通过$.fn 向jQuery添加新的方法

<div class="table-container">
<ul class="table-title clearfix" >
<li class="active">第一</li>
<li>第二</li>
<li>第三</li>
<li>第四</li>
</ul>
<div class="table-content-wrap">
<div class="table-content active">111</div>
<div class="table-content">222</div>
<div class="table-content">333</div>
<div class="table-content">444</div>
</div>
</div>
<div class="table-container">
<ul class="table-title clearfix" >
<li class="active">第一</li>
<li>第二</li>
<li>第三</li>
<li>第四</li>
</ul>
<div class="table-content-wrap">
<div class="table-content active">1111</div>
<div class="table-content">2222</div>
<div class="table-content">3333</div>
<div class="table-content">4444</div>
</div>
</div>

 

.table-container{width:460px;height: 460px;margin:50px auto;border: 1px solid #ddd;padding:30px;color: #333;}
.table-title{height:50px;line-height: 50px;text-align: center;font-size: 14px;}
.table-title li{width: 25%;cursor:pointer;float: left;}
.table-title li{cursor:pointer;float: left;}
.table-title li.active{background: grey;color: #fff;}
.table-content-wrap>div{height: 350px;text-align: center;line-height: 350px;}
.table-content-wrap>div{width:100%;padding: 20px;display: none;}
.table-content-wrap>div:nth-child(1){background: pink;}
.table-content-wrap>div:nth-child(2){background: grey;}
.table-content-wrap>div:nth-child(3){background: yellowgreen;}
.table-content-wrap>div:nth-child(4){background: purple;}
.table-content-wrap>div.active{display: block;}

 

 

;(function($) {
$.fn.tableSwitch = function() {
return this.each(function() {

var tableEl = $(this).children('.table-title').find('li'),
tableCon = $(this).find('.table-content');
tableEl.click(function(event) {
var i = $(this).index();
switchClass(tableEl, 'li');
switchClass(tableCon, 'div');
function switchClass(el, elName) {
el.eq(i).addClass('active').siblings(elName).removeClass('active');
}

})
})
}

$('.table-container').tableSwitch();


})(jQuery);

转载于:https://www.cnblogs.com/xiaomaotao/p/7273573.html

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值