HTML全选和反选的按钮代码,还是感觉这种按钮爽!

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>cyberobject.com - checkbox seclet or disselect all</title>
<script language="JavaScript">
<!--
function checkboxselect(itemname,checkstatus) {
if(!itemname) return;
if(!itemname.length) {
itemname.checked=checkstatus;
} else {
for(var i=0;i<itemname.length;i++) {
   itemname[i].checked=checkstatus;
}
}
}
//-->
</script>
</head>
<body>
<form name="form1" method="post" action="">
<p>
    <input type="checkbox" name="zone_checkbox" value="zone_checkbox" onClick="checkboxselect(document.form1.checkbox, document.form1.zone_checkbox.checked)">全选
</p>
<p>   
    <input type="checkbox" name="checkbox" id="checkbox" value="1">1 <br>
    <input name="checkbox" type="checkbox" id="checkbox" value="2">2 <br>
    <input name="checkbox" type="checkbox" id="checkbox" value="3">3 <br>
    <input name="checkbox" type="checkbox" id="checkbox" value="4">4 <br>
    <input name="checkbox" type="checkbox" id="checkbox" value="5">5 <br>
    <input name="checkbox" type="checkbox" id="checkbox" value="6">6
</p>
<p>
    <input type="submit" name="Submit" value="清除">
</p>
</form>
</body>
</html>

 

全选按钮代码 反选按钮代码

以下是Android购物车实现全选反选代码实现,供参考: 1. 在购物车列表中添加一个全选CheckBox,并设置其状态为未选中: ``` CheckBox cbSelectAll = findViewById(R.id.cb_select_all); cbSelectAll.setChecked(false); ``` 2. 在Adapter中实现全选反选的逻辑: ``` public class ShoppingCartAdapter extends RecyclerView.Adapter<ShoppingCartAdapter.ViewHolder> { // 全选状态 private boolean isSelectAll = false; // 全选按钮的点击事件 public void selectAll() { isSelectAll = !isSelectAll; notifyDataSetChanged(); } // 反选按钮的点击事件 public void reverseSelect() { isSelectAll = false; notifyDataSetChanged(); } // 获取全选状态 public boolean isSelectAll() { return isSelectAll; } // ViewHolder中的CheckBox的点击事件 @Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) { final Goods goods = mGoodsList.get(position); holder.cbSelected.setChecked(goods.isSelected()); holder.cbSelected.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { goods.setSelected(!goods.isSelected()); notifyDataSetChanged(); } }); } // 全选反选的实现 @Override public void onBindViewHolder(@NonNull ViewHolder holder, int position) { final Goods goods = mGoodsList.get(position); holder.cbSelected.setChecked(goods.isSelected()); holder.cbSelected.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { goods.setSelected(!goods.isSelected()); if (isSelectAll()) { for (Goods g : mGoodsList) { if (!g.isSelected()) { isSelectAll = false; break; } } } else { boolean isAllSelected = true; for (Goods g : mGoodsList) { if (!g.isSelected()) { isAllSelected = false; break; } } if (isAllSelected) { isSelectAll = true; } } notifyDataSetChanged(); } }); } // 全选按钮的状态改变 public void updateSelectAllState() { boolean isAllSelected = true; for (Goods g : mGoodsList) { if (!g.isSelected()) { isAllSelected = false; break; } } isSelectAll = isAllSelected; notifyDataSetChanged(); } } ``` 3. 在全选按钮的点击事件中,调用Adapter的selectAll()和reverseSelect()方法: ``` CheckBox cbSelectAll = findViewById(R.id.cb_select_all); cbSelectAll.setOnClickListener(new View.OnClickListener() { @Override public void onClick(View v) { if (mAdapter.isSelectAll()) { mAdapter.reverseSelect(); } else { mAdapter.selectAll(); } } }); ``` 通过以上代码实现,就可以实现Android购物车的全选反选功能了。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值