select 全选和反选 jquery

 
  1. <html>
  2. <head>
  3. <script src="jquery.js"></script>
  4. <script type="text/javascript"
  5. $(function() { 
  6. //全选
  7. $("#selectall").click(function() { 
  8. $("input[@name='shareuser']").each(function() { 
  9. $(this).attr("checked"true); 
  10. }); 
  11. }); 
  12. //反选
  13. $("#fanall").click(function() { 
  14. $("input[@name='shareuser']").each(function() { 
  15. if($(this).attr("checked"))
  16. {
  17. $(this).attr("checked"false); 
  18. }
  19. else
  20. {
  21. $(this).attr("checked"true); 
  22. }
  23. }); 
  24. }); 
  25. //取消全部
  26. $("#deselectall").click(function() { 
  27. $("input[@name='shareuser']").each(function() { 
  28. $(this).attr("checked"false); 
  29. }); 
  30. }); 
  31. //alert
  32. $("#alertall").click(function() { 
  33. $("input[@name='shareuser']").each(function() { 
  34. if($(this).attr("checked"))
  35. {
  36. alert($(this).val());
  37. }
  38. }); 
  39. }); 
  40.  
  41. }); 
  42. </script> 
  43.  
  44. <input type='checkbox' id='in-shareuser-10' name='shareuser' value='10' />10 
  45. <input type='checkbox' id='in-shareuser-11' name='shareuser' value='11' />11
  46. <input type='checkbox' id='in-shareuser-12' name='shareuser' value='12' />12 
  47.  
  48. <input type="button" id="selectall" name="selectall" value="全选" /> 
  49. <input type="button" id="fanall" name="fanall" value="反选" /> 
  50. <input type="button" id="deselectall" name="deselectall" value="取消" /> 
  51. <input type="button" id="alertall" name="alertall" value="输出" /> 
删除之类操作需要全选功能,方便选择 public class MainActivity extends Activity { private ListView lv; private MyAdapter mAdapter; private ArrayList list; private Button bt_selectall; // private Button bt_cancel; // private Button bt_deselectall; private int checkNum; // 记录选中的条目数量 private TextView tv_show;// 用于显示选中的条目数量 /** Called when the activity is first created. */ @Override public void onCreate(Bundle savedInstanceState) { super.onCreate(savedInstanceState); setContentView(R.layout.activity_main); /* 实例化各个控件 */ lv = (ListView) findViewById(R.id.lv); bt_selectall = (Button) findViewById(R.id.bt_selectall); // bt_cancel = (Button) findViewById(R.id.bt_cancelselectall); // bt_deselectall = (Button) findViewById(R.id.bt_deselectall); tv_show = (TextView) findViewById(R.id.tv); list = new ArrayList(); // 为Adapter准备数据 initDate(); // 实例化自定义的MyAdapter mAdapter = new MyAdapter(list, this); // 绑定Adapter lv.setAdapter(mAdapter); // 全选按钮的回调接口 bt_selectall.setOnClickListener(new OnClickListener() { @Override public void onClick(View v) { // 遍历list的长度,将MyAdapter中的map值全部设为true for (int i = 0; i < list.size(); i++) { MyAdapter.getIsSelected().put(i, true); } // 数量设为list的长度 checkNum = list.size(); // 刷新listview和TextView的显示 dataChanged(); } }); // 反选按钮的回调接口 // bt_cancel.setOnClickListener(new OnClickListener() { // @Override // public void onClick(View v) { // // 遍历list的长度,将已选的设为未选,未选的设为已选 // for (int i = 0; i < list.siz
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值