jquery action bug for select options (IE8 Compatibility view mode) _jquery

Source: Internet
Author: User
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);
}
}
}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.