Get the App
SLTechnology News&Howtos  ›  Development  › 

How does jquery change the input property

Shulou Source: shulou.com Published: 2022-05-31 17:11:54 10月27日 Update

This article mainly explains "jquery how to change input properties", the content of the article is simple and clear, easy to learn and understand, the following please follow the editor's ideas slowly in depth, together to study and learn "how jquery changes input properties" bar!

Method: 1, with attr (), syntax "$(" input "). Attr (" attribute name "," attribute value ")", you can add the specified attribute or set the specified attribute to a new value; 2, with removeAttr (), the syntax "$(" input ") .removeAttr (" attribute name ") can delete the attribute.

The operating environment of this tutorial: windows7 system, jquery1.10.2 version, Dell G3 computer.

In jquery, you can change the attributes of a specified element by changing the value of the attribute or by removing the attribute. Let's take a closer look at it.

1. Use attr () to modify the attribute value

The attr () method sets the attribute value of the selected element.

You can set the specified property to a new value

When no attribute is specified, you can add it

Example: modify the input type property and change the text box to a time box

$(document) .ready (function () {$("button") .click (function () {$("input"). Attr ("type", "date");})

Modify the input property

Modify the input type property to change the text box to a time box

2. Delete attributes using removeAttr ()

The removeAttr () method removes attributes from the selected element.

$(document) .ready (function () {$("button") .click (function () {$("input"). RemoveAttr ("value");})

Modify the input property

Delete the input value property and clear the input box

Thank you for your reading, the above is the content of "how jquery changes input attributes". After the study of this article, I believe you have a deeper understanding of how jquery changes input attributes, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

Tags: Attributes elements methods learning content text time grammar can be passed that is ideas situations tutorials articles more versions environment computer knowledge knowledge points Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Apple Microsoft Shulou Tech Info MariaDB Docker