The Select label add method does not match the Error Type in IE6.

Source: Internet
Author: User
Document directory
  • Syntax

Select tags of HTML files

 

<Select multiple = "true" id = "seldealgoods" class = "selectmul">

</SELECT>

 

JS Code for adding Select Options

VaR newoption = document. createelement ('option'); <br/> if ($ ("# cherelate") [0]. checked) {<br/> newoption. TEXT = "bidirectional Association --" + selectgoods. options [I]. text; <br/> newoption. value = selectgoods. options [I]. value + "-Two"; <br/>}< br/> else {<br/> newoption. TEXT = "unidirectional Association --" + selectgoods. options [I]. text; <br/> newoption. value = selectgoods. options [I]. value + "-one"; <br/>}< br/> seldealgoods. add (newoption, null); <br/>

 

Selectgoods

For another select tag

The Code does not seem to have any problems. You can successfully Add the option when running on IE8 and ff. During IE6 testing, seldealgoods. Add (newoption, null );

The prompt type does not match.

Error

 

In w3school

View the Add Method

Syntax
selectObject.add(option,before)
Parameters Description
Option Required. The option element to add. It must be an option or optgroup element.
Before Required. Add a new element before the element in the option array. If this parameter is null, the element is added to the end of the Option array.

 

 

No syntax error. What is the problem? IE8 FF can achieve the effect, and IE6 is not compatible.
View the sample code given by w3cschool

<HTML> <br/> <pead> <br/> <MCE: Script Type = "text/JavaScript"> <! -- <Br/> function insertoption () <br/>{< br/> var y = document. createelement ('option'); <br/> Y. TEXT = 'kiw' <br/> var x = document. getelementbyid ("myselect"); <br/> try <br/>{< br/> X. add (Y, null); // standards compliant <br/>}< br/> catch (Ex) <br/>{< br/> X. add (y); // ie Only <br/>}< br/> // --> </MCE: SCRIPT> <br/> </pead> <br/> <body> <br/> <form> <br/> <select id = "myselect"> <br/> <option> Apple </option> <br/> <option> pear </option> <br/> <option> banana </option> <br/> <option> orange </option> <br/> </SELECT> <br/> <input type = "button" onclick = "insertoption () "<br/> value =" insert option "/> <br/> </form> <br/> </body> <br/> </ptml>

 

When calling the add method, you can see that there is a try catch exception capture, and the catch shows that IE uses X. Add (y)
That is to say, ie support

SelectObject. Add (option), so the JS Code is changed
VaR newoption = document. createelement ('option'); if ($ ("# cherelate") [0]. checked) {newoption. TEXT = "bidirectional Association --" + selectgoods. options [I]. text; newoption. value = selectgoods. options [I]. value + "-Two";} else {newoption. TEXT = "unidirectional Association --" + selectgoods. options [I]. text; newoption. value = selectgoods. options [I]. value + "-one";} Try {seldealgoods. add (newoption, null);} catch (Ex) {seldealgoods. add (newoption );}

Running properly

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.