Set the Select Drop-down menu to readonly read-only code instances

Source: Internet
Author: User
Antzone Current offline integral 31318

Set the Select Drop-down menu to readonly read-only code instances:
The Select Pull-down menu has no readonly attributes, and sometimes we want it to be read-only, and some friends may think of setting it as disabled unavailable, but this time the Select Drop-down menu data cannot be submitted, so it's not feasible. Here is a description of how to simulate the implementation of the Drop-down menu read-only effect, the way to achieve multiple, the following introduction of several commonly used methods.
I. Using a script to fix the selected item:
Setting to read-only means that you cannot select other items by using the script to fix the selected option.
The code is as follows:
[HTML] Plain text view copy code run code?
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27-28 <! DOCTYPE html> < HTML > < head > < META charset = "Utf-8" > < meta name = "Author" content = "http: www.softwhy.com/"/> < title > Ant Tribe </title > < script type =" Text/javascript "> Window.onload=func tion () {   var Osel=document.getelementbyid ("sel");    osel.onfocus=function () {      This.defaultindex=this.selectedindex;   }    osel.onchange=function () {     This.selectedindex=this.defaultindex ;   } </script >
The above code simulation implements the ReadOnly read-only effect, the code is simpler to introduce, you can see the JavaScript select Object Chapter.
two. Set drop down menu is not available, write value value to hidden box:
You can set the Select Drop-down menu to be unavailable, although the Drop-down menu cannot be committed, but you can assign a Drop-down menu value to a hidden control so that you can submit a hidden control with the following code: [HTML] Plain text view copy code run code?
01 02 03 04 05 06 07 08 09 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24-25 <! DOCTYPE html> < HTML > < head > < META charset = "Utf-8" > < meta name = "Author" content = "http: www.softwhy.com/"/> < title > Ant Tribe </title > < script type =" Text/javascript "> Window.onload=func    tion () {var Osel=document.getelementbyid ("Sel");    var Ohid=document.getelementbyid ("hid"); Ohid.value=osel.value; </script >

three. Set to unavailable before submission, set to available when submitting:
You can set the Drop-down menu to disabled before submitting the form, but it is set to be available when the form is submitted, which not only enables read-only effects, but also submits data, as follows: [JavaScript] Plain text view copy code run code?
1 2 3 4 5 6 7 8 </

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.