Ext Core实现Checkbox的全选

来源:互联网 发布:淘宝上有哪些促销活动 编辑:程序博客网 时间:2024/05/18 09:10

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

1,新建一个 check_all_none.html.

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

1,新建一个 check_all_none.html.

view source
print?
01.<!DOCTYPE html PUBLIC"-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
02.<html>
03.<head>
04.<meta http-equiv="Content-Type"content="text/html; charset=UTF-8">
05.<title>选中列表中的所有Checkbox</title>
06.<script type="text/javascript"src="../../ext-core-debug.js"></script>
07.<script type="text/javascript"src="check_all_none.js"></script>
08.<link rel="stylesheet"href="check_all_none.css" />
09.</head>
10.<body>
11.<table id="fun"border="0" align="center" cellpadding="0"cellspacing="1">
12. <tr id="header">
13.   <td width="25"><input type="checkbox"id="checkall" name="checkall"></td>
14.   <td>Name</td>
15. </tr>
16. <tr>
17.   <td>
18.     <input type="checkbox"value="1" id="funcode[]" name="funcode[]"></td>
19.   <td>ExtCore 1</td>
20. </tr>
21. <tr>
22.   <td>
23.     <input type="checkbox"value="2" id="funcode[]" name="funcode[]"></td>
24.   <td>ExtCore 2</td>
25. </tr>
26. <tr>
27.   <td>
28.     <input type="checkbox"value="3" id="funcode[]" name="funcode[]"></td>
29.   <td>ExtCore 3</td>
30. </tr>
31. <tr>
32.   <td>
33.     <input type="checkbox"value="4" id="funcode[]" name="funcode[]"></td>
34.   <td>ExtCore 4</td>
35. </tr>
36. <tr>
37.   <td>
38.     <input type="checkbox"value="5" id="funcode[]" name="funcode[]"></td>
39.   <td>ExtCore 5</td>
40. </tr>
41. <tr>
42.   <td>
43.     <input type="checkbox"value="6" id="funcode[]" name="funcode[]"></td>
44.   <td>ExtCore 6</td>
45. </tr>
46. <tr>
47.   <td>
48.     <input type="checkbox"value="7" id="funcode[]" name="funcode[]"></td>
49.   <td>ExtCore 7</td>
50. </tr>
51. <tr>
52.   <td>
53.     <input type="checkbox"value="8" id="funcode[]" name="funcode[]"></td>
54.   <td>ExtCore 8</td>
55. </tr>
56. <tr>
57.   <td>
58.     <input type="checkbox"value="9" id="funcode[]" name="funcode[]"></td>
59.   <td>ExtCore 9</td>
60. </tr>
61. </tbody>
62.</table>
63.<p style="text-align:center; font-size:18px;">© 2010 <a href="http://extjs.org.cn"target="_blank">ExtJs.org.cn</a> | <script type="text/javascript">eval(unescape('%64%6f%63%75%6d%65%6e%74%2e%77%72%69%74%65%28%27%3c%61%20%68%72%65%66%3d%22%6d%61%69%6c%74%6f%3a%65%78%74%6a%73%63%6e%40%31%32%36%2e%63%6f%6d%22%3e%65%78%74%6a%73%63%6e%40%31%32%36%2e%63%6f%6d%3c%2f%61%3e%27%29%3b'))</script><a href="mailto:extjscn@126.com">extjscn@126.com</a> </p>
64.</body>
65.</html>
2,新加一个被引用的 check_all_none.js .
view source
print?
01.Ext.onReady(function(){
02.Ext.get('checkall').on('click',function(){
03. if(this.dom.checked){
04.  Ext.select('input[name^=funcode]').each(function(){this.dom.checked = true;});
05. }else{
06.  Ext.select('input[name^=funcode]').each(function(){this.dom.checked = false;});
07. 
08.});    
09.});

原创粉丝点击