Js makes the drop-down list box editable not only select

Source: Internet
Author: User

Js makes the drop-down list box editable not only select

The drop-down list box cannot be edited by default. The following describes a good way to edit the drop-down list box. The specific implementation is as follows. For more information, see

The Code is as follows:

<Script>

Function clearOption (obj, e ){

Var currKey = 0, e = e | event;

CurrKey = e. keyCode | e. which | e. charCode;

If (currKey = 8 ){

Obj. options [0]. text = "";

}

}

Function writeSelect (obj, e ){

Var currKey = 0, e = e | event;

CurrKey = e. keyCode | e. which | e. charCode;

Obj. options [0]. selected = "select ";

If (currKey! = 8) {// This part is intended to avoid annoying Garbled text in firefox. You can try to comment this sentence to see the effect in firefox.

Obj. options [0]. text = obj. options [0]. text + String. fromCharCode (currKey );

}

E. returnValue = false;

Return obj. options [0]. text;

}

Function ttt (){

Var jg = document. getElementById ("aa"). options [document. getElementById ("aa"). selectedIndex]. text;

// Of course, you can also set the options value in the previous writeSelect function. In this way, you can use the value in the program to retrieve the value.

JQuery ("# aa"). empty ();

JQuery ("# aa"). append ("<option value =''> </option> ");

}

 

</Script>

 

The Code is as follows:

<Select style = 'width: 150px; z-index:-1 'id = "aa" name = "selectHelpCode" onkeydown = "clearOption (this, event) "onkeypress =" writeSelect (this, event) ">

<Option value = ""> </option>

<Option value = "11"> 11 </option>

<Option value = "22"> 22 </option>

<Option value = "33"> 33 </option>

</Select>

<Input type = "button" value = "clear" onclick = "ttt ();"/>

 

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.