IE6 7 select option setting disabled is invalid

Source: Internet
Author: User

A category of system documents needs to be disabled (notDelete), The form for making the document is the drop-down list used, and immediately thought of the option disabled.

 
1:FunctionDiableselectitem (ID, v ){
 
2:VaREl = Document. getelementbyid (ID );
 
3:For(VaRI = 0, j = El. Options. length; I <j; I ++ ){
 
4:If(EL. Options [I]. value = V) {El. Options [I]. Disabled =True;Break;}
 
5:}
 
6:}

OK, run, found that the option is not displayed in gray, still available .!!!CodeNo problem. What should I do? I tried to use IE8 in a whim and disabled it. Nnd is an IE Problem

What should I do? If there is a problem, find Google and find select, option, disabled and the Javascript Solution

Some foreigners have done it. Code:

1:/*************************************** *************************
 
2:* Author: Alistair lattimore
 
3:* Website: http://www.lattimore.id.au/
 
4:* Contact: http://www.lattimore.id.au/contact/
 
5:* Errors, suggestions or comments
 
6:* Date: 30 Jun 2005
 
7:* Version: 1.0
8:* Purpose: emulate the disabled attributte for the <option>
 
9:* Element in Internet Explorer.
 
10:* Use: You are free to use this script in non-essential cial
 
11:* Applications. You are however required to leave
 
12:* This comment at the top of this file.
 
13:*
 
14:* I 'd love an email if you find a use for it on your
15:* Site, though not required.
 
16:**************************************** ************************/
 
17: 
 
18:Window. onload =Function(){
 
19:If(Document. getelementsbytagname ){
 
20:VaRS = Document. getelementsbytagname ("Select");
 
21: 
 
22:If(S. length> 0 ){
23:Window. select_current =NewArray ();
 
24: 
 
25:For(VaRI = 0, select; select = s [I]; I ++ ){
 
26:Select. onfocus =Function() {Window. select_current [This. ID] =This. Selectedindex ;}
 
27:Select. onchange =Function() {Restore (This);}
 
28:Emulate (select );
 
29:}
30:}
 
31:}
 
32:}
 
33: 
 
34:FunctionRestore (e ){
 
35:If(E. Options [E. selectedindex]. Disabled ){
 
36:E. selectedindex = Window. select_current [E. ID];
 
37:}
 
38:}
 
39: 
 
40:FunctionEmulate (e ){
41:For(VaRI = 0, option; option = E. Options [I]; I ++ ){
 
42:If(Option. Disabled ){
 
43:Option. style. Color ="Graytext";
 
44:}
 
45:Else{
 
46:Option. style. Color ="Menutext";
 
47:}
 
48:}
 
49:}

Simulates the Disabled Effect and changes the text color. When an option has the disabled attribute, the Select element selects the index rollback default value.

The JS Code for judging the IE version comes from situ zhengmei.

 
1:VaRIe = (Function(){
2:VaRV = 3, DIV = Document. createelement ('Div'), A = div. All | [];
 
3:While(Div. innerhtml ='<! -- [If GT Ie'+ (++ V) +']> <Br> <! [Endif] -->', A [0]);
 
4:ReturnV> 4? V :! V;
 
5:}());

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.