Home  >  Article  >  Web Front-end  >  The disabled attribute cannot read data in the background. How to make select support readonly?

The disabled attribute cannot read data in the background. How to make select support readonly?

高洛峰
高洛峰Original
2017-03-02 14:43:502222browse

After setting the disabled attribute, the data cannot be read in the background. If you want select to support the readonly attribute, you can set the disabled attribute and store the form value in the hidden field. You can also use jquery to control it. The example is as follows, friends who need it should not miss it

<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》Set the readonly attribute of the form
Problem: But 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 data cannot be read in the background

Method:

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

Code:

Quote jquery file

875fec92d8feb85a43990fb5622708002cacc6d41bbb37262a98f745aa00fbf0

Use script to control the disabled attribute

<span style="font-family:Microsoft YaHei;"><script type="text/javascript"> 
//加载时设置disabled生效 
$(document).ready(function(){ 
$("input[name=category]").attr("disabled",true); 
$("select[name=sonota_kbn]").attr("disabled",true); 
}); 
//提交时设置disabled失效 
$("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


More disabled attributes cannot read data in the background. How to make select support readonly. For related articles, please pay attention to the PHP Chinese website!


Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn