带复选框且支持搜索功能的下拉列表7

本文介绍了一个全选功能的具体实现方式,通过JavaScript代码展示了如何在列表中实现全选和取消全选的功能。该功能通过修改复选框的状态来更新显示值,并触发选择事件。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >


// private
onSelect : function(record, index)
{
/*
* 增加一个全选功能,ckf36476
*/
if (index == 0)
{
var r_qx = this.store.getAt(index);
var newValue_qx = r_qx.data[this.displayField];
var check_qx = document.getElementById("checkBox_" + newValue_qx);
if (check_qx.className == "checked")
{
check_qx.className = "unchecked"
}
else
{
check_qx.className = "checked"
}
for (var i = 1; i < this.store.data.length; i++)
{
var r = this.store.getAt(i);
var newValue = r.data[this.displayField];
var check = document.getElementById("checkBox_" + newValue);
if (check_qx.className == "checked")
{
check.className = "checked"
}
else
{
check.className = "unchecked"
}
}
var value = "";
var hiddenValue = "";
for (var i = 0; i < this.store.data.length; i++)
{
var r = this.store.getAt(i);
newValue = r.data[this.displayField];
check = document.getElementById("checkBox_" + newValue);
if (check.className == "checked")
{
value += r.data[this.displayField] + this.displaySeparator;
hiddenValue += r.data[this.valueField] + this.valueSeparator;
}
}
if (value.length > 1)
{
value = value.substring(0, value.length - this.displaySeparator.length);
}
if (hiddenValue.length > 1)
{
hiddenValue = hiddenValue.substring(0, value.length - this.valueSeparator.length);
}
this.setValue(value);
this.hiddenField.value = hiddenValue;
this.fireEvent('select', this, record, index);
return;
}
//全选结束


if (this.fireEvent('beforeselect', this, record, index) !== false)
{
var r = this.store.getAt(index);
var newValue = r.data[this.displayField];
var check = document.getElementById("checkBox_" + newValue);
if (check.className == "checked")
{
check.className = "unchecked"
}
else
{
check.className = "checked"
}
var value = "";
var hiddenValue = "";
for (var i = 0; i < this.store.data.length; i++)
{
var r = this.store.getAt(i);
newValue = r.data[this.displayField];
check = document.getElementById("checkBox_" + newValue);
if (check.className == "checked")
{
value += r.data[this.displayField] + this.displaySeparator;
hiddenValue += r.data[this.valueField] + this.valueSeparator;
}
}
if (value.length > 1)
{
value = value.substring(0, value.length - this.displaySeparator.length);
}
if (hiddenValue.length > 1)
{
hiddenValue = hiddenValue.substring(0, value.length - this.valueSeparator.length);
}
this.setValue(value);
this.hiddenField.value = hiddenValue;
this.fireEvent('select', this, record, index);
}
},
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值