创建一个数组并使用if not already in thereselected
添加new
选择(像这样然后当未选中时像这样并循环剩余选项,使用push
if(selected.indexOf(new) < 0)selected.push(new);
splice
selected.splice(selected.indexOf(unchecked),1)
indexOf + 1
所以用英文和你的代码(我用了你的名字,所以它只适合你)
var selected = [];
function enableDisable(checked, id){//checked = this.checked id = this.id
if(!checked){
selected.push(id);
//write drop-down
} else {
selected.splice(selected.indexOf(id),1);
for(var i in selected) {
slctEleme = document.getElementById("slct" + selected[i].substr(selected[i].length - 1),0);
slctElem.innerHTML = "";
for (var j in selected)
slctElem.innerHTML += "<option value = '"+(j+1)+"'"
if ( i = j ) slctElem.innerHTML += "selected";
slctElem.innerHTML += ">" +(j+1)+ "</option >";
}
}
}
当他们更改选择时,您还可以更改数组中值的索引,与此代码一起使用,他们将通过复选框更改来保持选择。再次查看 jquery,这只是一个 javascript 尝试。