从原来的代码链接(Populate another select dropdown from database based on dropdown selection)
不得不改变该位: -
function updateSubCats(){
var catSelect = this;
var catid = this.value;
var subcatSelect = document.getElementById("subcatsSelect");
subcatSelect.options.length = 0; //delete all options if any present
for(var i = 0; i < subcats[catid].length; i++){
subcatSelect.options[i] = new Option(subcats[catid][i].val,subcats[catid][i].id);
}
这样: -
function updateSubCats(){
var catSelect = this;
var catid = this.value;
var testSelectionArray = new Array();
for(var j = 0; j < this.options.length; j++) {
if (this.options[j].selected) {
testSelectionArray.push(this.options[j].value);
}
}
var subcatSelect = document.getElementById("subcatsSelect");
subcatSelect.options.length = 0; //delete all options if any present
var k=0;
for(var i = 0; i < testSelectionArray.length; i++){
catid = testSelectionArray[i];
for(var j = 0; j < subcats[catid].length; j++){
subcatSelect.options[k++] = new Option(subcats[catid][j].val,subcats[catid][j].id);
}
}
}
谢谢,我就会有一个看看jQuery的变化。我已经添加了我的代码,虽然我甚至遇到了jsfiddle的麻烦! – 2015-02-10 15:03:47
你不能在jsfiddle上使用php,例如为什么我们试着把php拿出来,只是把填充值从db中拿出来:) - 隔离问题 – 2015-02-10 15:41:36
好吧,我已经摆脱了PHP,但仍然没有相当有... – 2015-02-10 16:44:07