Bug Scene:
With developer tools, the Drop-down list box has options, but you don't show anything when you click on the selection.
Recurrence Steps:
The problem occurs in a cascading dropdown box where the first list changes and the value of the second list changes accordingly!
This example uses the following methods to bind the data:
Copy Code code as follows:
Tie Down Pull Box
Ctnselector: dropdown box ID, with # number,
Jsondata:json data,
Txtfield: Text field name,
Valfield: Value field name,
Stroptions: Default-filled items
function Initselectoptions (Ctnselector, Jsondata, Txtfield, Valfield, stroptions) {
if ($ (ctnselector). length = = 0) {return false;};
$ (ctnselector). html (');
var optlist = stroptions;
if (typeof (Jsondata)!= undefined) {
for (Var jitem in Jsondata) {
if (Jitem = = "InsertAt" | | | jitem = "RemoveAt" | | jitem = = "MoveTo") {
Continue Solve problems caused by flareJ.Base.js.
}
Optlist + + "<option value= '" + Jsondata[jitem][valfield] + "' >" + Jsondata[jitem][txtfield] + "</option>";
}
}
$ (ctnselector). HTML (optlist);
}
Normal load without any problems!
But when the value of the first Drop-down box is changed and the second dropdown box is emptied,
And then you go to point a second Drop-down box and try to select one,
To change the options for the first Drop-down box,
You'll notice that the item in the second Drop-down box that corresponds to the first Drop-down box is not displayed.
Only the first one is displayed, or the script is set to the selected one!
Solution:
Using the DOM method to manipulate options, the code is as follows:
Copy Code code as follows:
Tie Down Pull Box
Ctnselector: dropdown box ID, with # number,
Jsondata:json data,
Txtfield: Text field name,
Valfield: Value field name,
Stroptions: Default-filled items
function Initselectoptions (Ctnselector, Jsondata, Txtfield, Valfield, stroptions) {
if ($ (ctnselector). length = = 0) {return false;};
$ (ctnselector). empty ();
var sel = $ (ctnselector). Get (0);
var newopt = $ (stroptions);
var newOption1 = document.createelement ("option");
Newoption1.text = Newopt.text ();
Newoption1.value = Newopt.val ();
Sel.options.add (NewOption1);
if (typeof (Jsondata)!= undefined) {
for (Var jitem in Jsondata) {
if (Jitem = = "InsertAt" | | | jitem = "RemoveAt" | | jitem = = "MoveTo") {
Continue Solve problems caused by flareJ.Base.js.
}
var newoption = document.createelement ("option");
Newoption.text = Jsondata[jitem][txtfield];
Newoption.value = Jsondata[jitem][valfield];
Sel.options.add (newoption);
}
}
}