html代码:

<!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>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>checkbox plugin</title>
<script type="text/javascript" src="../jquery-1.8.2.js"></script>
<script type="text/javascript" src="check.js"></script>
<!--
<script type="text/javascript" src="check2.js"></script>
-->
<script type="text/javascript" src="check3.js"></script>
</head> <body>
<div>
<button onclick="CheckAll();">选择全部</button>
<button onclick="UnCheckAll();">清除全部</button>
<hr />
<input type="checkbox" id="checkall" />全选<br />
<input type="checkbox" id="c2" />测试<br />
<input type="checkbox" id="Checkbox1" />测试<br />
<input type="checkbox" id="Checkbox2" />测试<br />
<input type="checkbox" id="Checkbox3" />测试<br />
<input type="checkbox" id="Checkbox4" />测试<br />
<input type="checkbox" id="Checkbox5" />测试<br />
<input type="checkbox" id="Checkbox6" />测试<br />
<input type="checkbox" id="Checkbox7" />测试<br />
<input type="checkbox" id="Checkbox8" />测试<br />
<input type="checkbox" id="Checkbox9" />测试<br />
<input type="checkbox" id="Checkbox10" />测试<br />
</div> <script type="text/javascript">
function CheckAll(){
$('input:checkbox').check();
}
function UnCheckAll(){
$('input:checkbox').uncheck();
} $(function(){
//$('input:checkbox').tukiCheck();
$.tukiCheck('checkall');
});
</script>
</body>
</html>

js代码一:

jQuery.fn.extend({
check: function(){
return this.each(function(){this.checked = true;}); //return a jquery object
},
uncheck: function(){
return this.each(function(){this.checked = false;});
}
});

此段js插件开发为对象级别插件开发,即给jquery对象方法。

hml中调用的时候,先引入js,然后点击事件触发方法即可。

$('input:checkbox').check();

$('input:checkbox').uncheck();

js代码二:

 (function($){
var methods = {
init: function(options){
return this.each(function(){
var settings = $.extend({}, options); var $this = $(this); $this.click(function() {
var ckId = $this.attr('id'); if (ckId == 'checkall') {
if ($this.attr('checked')) {
$this.siblings('input:checkbox').attr('checked', true);
} else {
$this.siblings('input:checkbox').attr('checked', false);
}
}
});
});
}
}; $.fn.tukiCheck = function(){
var method = arguments[]; if (methods[method]) {
method = methods[method];
arguments = Array.prototype.slice.call(arguments, );
} else if (typeof(method) == 'object' || !method) {
method = methods.init;
} else {
$.error( 'Method ' + method + ' does not exist on jQuery.pluginName' );
return this;
} return method.apply(this, arguments);
};
})(jQuery);

此插件开发为对象级别插件开发。也可以

(function($){

  $.fn.extend({

  })

})(jQuery)

html中调用:$('input:checkbox').tukiCheck();

js代码三:

 //tuki jquery ext
(function($, undefined){
var methods = {
checkall : function(){
var $chekcAllObj = $('#checkall'); if (undefined != $chekcAllObj) {
$chekcAllObj.click(function() {
var $this = $(this);
if ($this.attr('checked')) {
$this.siblings('input:checkbox').attr('checked', true);
} else {
$this.siblings('input:checkbox').attr('checked', false);
}
});
}
//return true;
}
}; $.tukiCheck = function(method) {
// Method calling logic
if (methods[method]) {
return methods[ method ].apply(this, Array.prototype.slice.call(arguments, ));
} else if (typeof method === 'object' || ! method) {
return methods.init.apply(this, arguments);
} else {
$.error('Method ' + method + ' does not exist on jQuery.tukibox');
}
};
})(jQuery);

此插件开发为类级别开发,即直接为jquery类本身添加方法。

html中调用:$.tukiCheck('checkall');

jquery插件开发(checkbox全选的简单实例)的更多相关文章

  1. jQuery实现CheckBox全选、全不选

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/ ...

  2. jQuery设置checkbox全选(区别jQuery版本)

    jQuery设置checkbox全选在网上有各种文章介绍,但是为什么在我们用他们的代码的时候就没有效果呢? 如果你的代码一点错误都没有,先不要急着怀疑人家代码的正确性,也许只是人家跟你用的jQuery ...

  3. jquery中checkbox全选失效的解决方法

    这篇文章主要介绍了jquery中checkbox全选失效的解决方法,需要的朋友可以参考下     如果你使用jQuery 1.6 ,代码if ( $(elem).attr(“checked”) ),将 ...

  4. 利用jQuery实现CheckBox全选/全不选/反选

    转自:http://www.cnblogs.com/linjiqin/p/3148259.html jQuery有些版本中实现CheckBox全选/全不选/反选会有bug,经测试jquery-1.3. ...

  5. Jquery 组 checkbox全选checkbox

    <!DOCTYPE html><html lang="zh-cn"><head> <meta charset="utf-8&qu ...

  6. 解决jquery操作checkbox全选全不选无法勾选问题

    最近在学习中使用jquery操作checkbox,使用下面方法进行全选.反选:$("input[name='checkbox']").attr("checked" ...

  7. jquery实现checkbox全选和全部取消,以及获取值

    在后台管理中经常会遇到列表全选和取消的功能,如评论审核.申请等,用到的html标记就是checkbox.我用的是mysql数据库,代码如下: <!DOCTYPE html PUBLIC &quo ...

  8. jquery的checkbox 全选和全不选

    今天写了一个checkbox的全选和全不选的功能: var check_all=function(){ if(this.checked){ //alert($(".adv_check_num ...

  9. jQuery实现checkbox全选反选及删除等操作

    1.list.html 说明:用checkbox数组Check[]存放每一行的ID值 <div id="con"> <table width="100% ...

随机推荐

  1. 自定义一个compass可编译的目录结构

    在学习compass的过程中, 根绝文档说明,如果使用compass create myObject命令会创建一个标准的Compass项目目录结构,如下图: 此时如果使用compass compile ...

  2. Adobe RIA

    一:1)Adobe® Flash® Player 是一个跨平台.基于浏览器的应用程序运行时,它可以跨屏幕和浏览器.原汁原味地呈现具有表现力的应用程序.内容和视频,当前版本Flash Player 10 ...

  3. Bad Request (Invalid Hostname)解决方法

    当在Windows Server 2003+IIS6做Web服务器,出现打开如http://paullevi.oicp.net,出现,Bad Request (Invalid Hostname) 的提 ...

  4. Serv-U软件在64位操作系统下使用不了odbc解决方法

    这是因为64位Windows上有两个ODBC连接,你需要创建一个32位的ODBC连接.打开32位ODBC管理器的位置 X:\Windows\syswow64\odbcad32.exe. 利用这个管理器 ...

  5. 设计模式之Memento(备忘机制)

    Memento备望录模式定义:memento是一个保存另外一个对象内部状态拷贝的对象.这样以后就可以将该对象恢复到原先保存的状态. Memento模式相对也比较好理解,我们看下列代码: public ...

  6. linux下Qt问题cannot find -lGL collect2: error: ld returned 1 exit status

    fedora下解决 yum groupinstall "Development Tools" yum install mesa-libGL-devel ubuntu下解决 sudo ...

  7. 设计模式_Bridge

    形象的例子: —早上碰到MM,要说早上好,晚上碰到MM,要说晚上好:碰到MM穿了件新衣服,要说你的衣服好漂亮哦,碰到MM新做的发型,要说你的头发好漂亮哦.不要问我“早上碰到MM新做了个发型怎么说”这种 ...

  8. zabbix监控域名带宽

    代码地址:https://github.com/Ma-Jing/python/blob/master/ngxv2_traffic_daemon.py READ.md里有使用说明! #!/usr/bin ...

  9. 利用迅雷提供的接口从磁力链得到bt种子文件

    本地下载工具的磁力链下载速度不给力,而百度云盘有提供离线下载服务,相当于就是直接到服务器取个链接而已.但这需要bt文件,而我只有链力链.网上搜了一下,可以从磁力链构造一个bt文件的下载地址,用pyth ...

  10. HDU-1402 A * B Problem Plus FFT(快速傅立叶变化)

    题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=1402 一般的的大数乘法都是直接模拟乘法演算过程,复杂度O(n^2),对于这题来说会超时.乘法的过程基本 ...