從原來的代碼鏈接(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