JQuery to control hidden disable and other methods of no value properties

  • 2020-03-30 01:16:06
  • OfStack

Typically, we put a few hidden properties when we implement some form submission pages

For example, when a record is modified, the id of that record is embedded in the edit window

In the presentation interface, it is sometimes necessary to disable the input or select box to avoid user modification

Hidden in the following code does not work properly in IE
 
<input name = "role_name" id = "role_name" value="Roy" disabled> 
<input name = "role_id" id = "role_id" hidden value="3312"> 

Standard writing should add value
 
<input name = "role_name" id = "role_name" value="Roy" disabled = "disabled"> 
<input name = "role_id" id = "role_id" hidden = "hidden" value="3312"> 

Sometimes we need to edit the above two on the current page. How do we do this

We can use
 
$("#role_name").removeAttr("disabled"); 
$("#role_id").removeAttr("hidden"); 

or
 
$("#role_name").prop("disabled",false); 
$("#role_id").prop("hidden",false); 

The $("#role_name").prop() returns a Boolean value to verify that the property prop() method is enabled and can also be used in checked to control whether the option is selected

Prop () normally takes effect when the property name is written and can use a Boolean to manipulate the property state

Related articles: