Home > Web Front-end > JS Tutorial > 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
Release: 2018-09-30 16:46:44
Original
1881 people have browsed it

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">
Copy after login

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">
Copy after login

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");
Copy after login

or

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

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!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template