Ext Core实现Checkbox的全选

 

1,新建一个 check_all_none.html.

全选/不选在很多时候我们都会使用到,在Ext Core出来之前,我一直使用纯javascript写的全选,反选.虽然可以实现,但代码始终还是不够简洁.现在我们使用Ext Core,简单的几句代码就可以实现这一个功能.
实现方法如下:

<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>选中列表中的所有Checkbox</title>
<script type="text/javascript" src="../../ext-core-debug.js"></script>
<script type="text/javascript" src="check_all_none.js"></script>
<link rel="stylesheet" href="check_all_none.css" />
</head>
<body>
<table id="fun" border="0" align="center" cellpadding="0" cellspacing="1">
  <tr id="header">
    <td width="25"><input type="checkbox" id="checkall" name="checkall"></td>
    <td>Name</td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" value="1" id="funcode[]" name="funcode[]"></td>
    <td>ExtCore 1</td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" value="2" id="funcode[]" name="funcode[]"></td>
    <td>ExtCore 2</td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" value="3" id="funcode[]" name="funcode[]"></td>
    <td>ExtCore 3</td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" value="4" id="funcode[]" name="funcode[]"></td>
    <td>ExtCore 4</td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" value="5" id="funcode[]" name="funcode[]"></td>
    <td>ExtCore 5</td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" value="6" id="funcode[]" name="funcode[]"></td>
    <td>ExtCore 6</td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" value="7" id="funcode[]" name="funcode[]"></td>
    <td>ExtCore 7</td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" value="8" id="funcode[]" name="funcode[]"></td>
    <td>ExtCore 8</td>
  </tr>
  <tr>
    <td>
      <input type="checkbox" value="9" id="funcode[]" name="funcode[]"></td>
    <td>ExtCore 9</td>
  </tr>
  </tbody>
</table>
<p style="text-align:center; font-size:18px;">© 2010 <a href="http://extjs.org.cn" target="_blank">ExtJs.org.cn</a> | extjscn@126.com </p>
</body>
</html>

 

 

2,新加一个被引用的 check_all_none.js .

 

Ext.onReady(function(){
 Ext.get('checkall').on('click',function(){
  if(this.dom.checked){
   Ext.select('input[name^=funcode]').each(function(){this.dom.checked = true;});
  }else{
   Ext.select('input[name^=funcode]').each(function(){this.dom.checked = false;});
  }  
 });    
});

3.css的引用

check_all_none.css

@charset "utf-8";
/* CSS Document */
#fun {
 background-color:#999;
 width:500px;
}
#fun td {
 background-color:#fff;
}
#header td {
 background-color:#333;
 color:#fff;
 font-weight:bold;
}

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值