首选定义数组,然后进行操作时遍历数组获取选中值
function getSelect(userId) { ???????????//var userId = userCheckBox.value; ???????????//标记删除还是添加 ???????????var isAdd = true; ???????????//如果已经存在,那么删除 ???????????for (var i = 0; i < this.UserIdArray.length; i++) { ???????????????//集合中是否存在用户id ???????????????if (this.UserIdArray[i] == userId) { ???????????????????//删除集合中的用户id ???????????????????this.UserIdArray = this.UserIdArray.splice(0, i).concat(this.UserIdArray.splice(i + 1, this.UserIdArray.length)); ???????????????????//标记是删除 ???????????????????isAdd = false; ???????????????????break; ???????????????} ???????????} ???????????//如果是添加,那么添加到数组 ???????????if (isAdd) { ???????????????this.UserIdArray.push(userId); ???????????}
操作方法
function Delete(){ ????if (this.UserIdArray.length < 1) { ???????????????alert("请选择要删除的数据!"); ???????????????return false; ???????????} ???????????else if (confirm("你确定要删除选中的数据吗?")) { ???????????????var str = ""; ???????????????for (var i = 0; i < this.UserIdArray.length; i++) { ???????????????????str += this.UserIdArray[i]; ???????????????????if (i + 1 != this.UserIdArray.length) { ???????????????????????str += ","; ???????????????????} ???????????????} ???????????????//str 即为选中值 ???}} ???
js 列表选择
原文地址:https://www.cnblogs.com/happygx/p/8979136.html