How to set the select to be read-only and not editable and the select value to be passable

How to set the select to be read-only and not editable and the select value to be passable
1. <select style="width:195px" name="role" id="role" onfocus="this.defaultIndex=this.selectedIndex;" onchange="this.selectedIndex=this.defaultIndex;">

This approach makes the drop-down box look the same as usual. The only difference is that after you pull down and select, it won’t respond to you. It’s the same whether you select it or not. It just ignores the customer's choice.

2. Set the disabled attribute <select style="width:195px" name="role" id="role" disabled="disabled">

This looks more direct, and it feels like read-only, and you can’t click or pull down. The words inside will also turn gray.

When the attribute is set to "disabled", the select value cannot be passed when the form is submitted. Remove the disabled attribute before submitting $("#role").removeAttr("disabled");

jquery adds the attribute $("#role").attr("disabled","disabled");

<<:  Nginx reverse proxy learning example tutorial

>>:  Five things a good user experience designer should do well (picture and text)

Recommend

Detailed examples of Linux disk device and LVM management commands

Preface In the Linux operating system, device fil...

Summary of the use of html meta tags (recommended)

Meta tag function The META tag is a key tag in th...

JS quickly master ES6 class usage

1. How to construct? Let's review the common ...

The iframe refresh method is more convenient

How to refresh iframe 1. To refresh, you can use j...

HTML+CSS makes div tag add delete icon in the upper right corner sample code

1. Requirements description Display the delete ic...

Introduction and use of triggers and cursors in MySQL

Trigger Introduction A trigger is a special store...

Understanding and application scenarios of enumeration types in TypeScript

Table of contents 1. What is 2. Use Numeric Enume...

Vue+ssh framework to realize online chat

This article shares the specific code of Vue+ssh ...

Ubuntu 20.04 sets a static IP address (including different versions)

Because Ubuntu 20.04 manages the network through ...

Teach you how to monitor Tomcat's JVM memory through JConsoler

Table of contents 1. How to monitor Tomcat 2. Jav...