Home  >  Article  >  Web Front-end  >  Methods to control valueless attributes such as hidden and disable in jQuery

Methods to control valueless attributes such as hidden and disable in jQuery

PHPz
PHPzOriginal
2016-05-16 17:05:131838browse

When implementing some form submission pages, several hidden attributes will be placed. Here is an introduction to how to control valueless attributes such as hidden and disable in jQuery. Friends who are interested should not miss it.

Generally when we implement some form submission pages, we will place some hidden attributes. For example, when modifying a record, the id of the record will be embedded in the editing window.

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

The 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">

The standard writing method should have added 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 current page as above Two, what should be done at this time?

We can use:

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

or

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

where $("#role_name").prop() will return a boolean value to confirm whether it has been The prop() method that turns on this attribute can also be used in the checked option to control whether the option is selected.

Generally, prop() can take effect by writing the attribute name and using boolean to control the attribute status.

The above is the entire content of this chapter. For more related tutorials, please visit jQuery Video Tutorial!

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