How to make select support readonly

Time:2019-12-26

Copy code

The code is as follows:

<span style=”font-family:Microsoft YaHei;”><select 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》 Set the readonly property of the form
Problem: but the readonly property has no effect on the three forms: Radio, select and checkbox

2》 Set the disabled property of the form

Problem: after the disabled property is set, the background cannot read the data

Way:

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

Code:

Reference jQuery file

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

Using script to control the disabled property

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);
});
//Disable disable on commit
$(“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 = name of category form

Recommended Today

Fourth, handwritten SpringMVC framework, business layer – what is coupling/dependency? How to solve

4. Business Layer 4.1 MVC model MVC:Model(Model),View(view),Controller(controller) View layer: an interface for displaying data and interacting with users=>jsp Control layer: It can accept the client's request and forward the request. The specific business function still needs to be completed with the help of the model layer component. CoreServlet  => DispacherServlet + EmpController Model layer: There are […]