How to make select support readonly when the background cannot read data when the disabled attribute is set

How to make select support readonly when the background cannot read data when the disabled attribute is set

Copy code
The code is as follows:

<span style="font-family:Microsoft YaHei;"><select id="lstTest" onfocus="this.defaultIndex=this.selectedIndex;" onchange="this.selectedIndex=this.defaultIndex;">
<option value="1">test1</option>
<option value="2">test2</option>
<option value="3" selected="selected">test3</option>
<option value="4">test4</option>
<option value="5">test5</option>
</select>
</span>

1》Problem of setting the readonly attribute of the form: However, the readonly attribute has no effect on the three forms of radio, select, and checkbox

2》Set the disabled attribute of the form

Problem: After setting the disabled attribute, the background cannot read data

way:

1. Set the disabled attribute and store the form value in the hidden field
2. Use jQuery to control (set the form attribute disabled=true when loading the page, and set the form attribute disabled=false when submitting the form)

Code:

Reference jquery file

<script type="text/javascript" src="../../js/jquery-1.3.2.js"></script>

Controlling the disabled attribute with scripts

Copy code
The code is as follows:

<span style="font-family:Microsoft YaHei;"><script type="text/javascript">
//Set disabled to take effect when loading
$(document).ready(function(){
$("input[name=category]").attr("disabled",true);
$("select[name=sonota_kbn]").attr("disabled",true);
});
//Set disabled to fail when submitting
$("input[name=modify]").click(function(){
$("input[name=category]").attr("disabled",false);
$("select[name=sonota_kbn]").attr("disabled",false);
});
</script> </span>

Note this: input[name=category]
Input is the form type (for example, select is a drop-down box)
name=category The name of the form

<<:  CSS float (float, clear) popular explanation and experience sharing

>>:  Detailed explanation of the English names corresponding to the font-family of Chinese fonts in CSS styles

Recommend

2 methods and precautions for adding scripts in HTML

How to add <script> script in HTML: 1. You c...

Introduction to CSS3 color value RGBA and gradient color usage

Before CSS3, gradient images could only be used a...

Call and execute host docker operations in docker container

First of all, this post is dedicated to Docker no...

Steps for importing tens of millions of data into MySQL using .Net Core

Table of contents Preliminary preparation Impleme...

Detailed explanation of Linux redirection usage

I believe that everyone needs to copy and paste d...

Methods for optimizing Oracle database with large memory pages in Linux

Preface PC Server has developed to this day and h...

Detailed explanation of CSS margin collapsing

Previous This is a classic old question. Since a ...

VUE+Express+MongoDB front-end and back-end separation to realize a note wall

I plan to realize a series of sticky note walls. ...

10 skills that make front-end developers worth millions

The skills that front-end developers need to mast...

Ubuntu basic settings: installation and use of openssh-server

Record the installation and use of openssh-server...

Analysis of Context application scenarios in React

Context definition and purpose Context provides a...

Detailed tutorial on compiling and installing MySQL 8.0.20 from source code

In the previous article, we introduced: MySQL8.0....