Get the App
SLTechnology News&Howtos  ›  Development  › 

How jquery changes the value property

Shulou Source: shulou.com Published: 2022-05-31 17:08:46 09月21日 Update

This article mainly introduces the relevant knowledge of "how jquery changes value attributes". The editor shows you the operation process through an actual case. The operation method is simple, fast and practical. I hope this article "how jquery changes value attributes" can help you solve the problem.

Three methods: 1, with "element object .val (" new value ")", you can modify the value of value attribute; 2, with "element object .attr (" value "," new value ")", you can modify value attribute value; 3, with "element object .removeAttr (" value ")", you can delete value attribute.

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

HTML value attribute

The value attribute specifies the value of the element. The value attribute is also used differently for different input types:

For "button", "reset", "submit" types-define text on buttons

For "text", "password", "hidden" types-define the initial (default) value of the input field

For "checkbox", "radio", "image" types-defines the value associated with the input element, which is sent to the action URL of the form when the form is submitted.

Where the value attribute is required for and. The value property does not apply to.

There are three ways for jquery to change the value attribute:

Use val () to modify the value of the value property

Use attr () to modify the value of the value property

Use removeAttr () to delete the value attribute

1. Use val () to modify the value of the value attribute

The val () method returns or sets the value of the selected element. The value of the element is set through the value attribute. This method is mostly used for input elements.

Example: clear the value of the value property

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

User name:

Secret code:

Modify the value of value

Clear the value attribute value for all input elements

2. Use attr () to modify the value of the value attribute

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

3. Delete the value attribute using removeAttr ()

RemoveAttr () is used to delete the specified attribute of the selected element

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

That's all for "how jquery changes value properties". Thank you for reading. If you want to know more about the industry, you can follow the industry information channel. The editor will update different knowledge points for you every day.

Tags: Attributes elements methods types different objects knowledge industry forms utility discomfort content fields practicality practical buttons tutorials text articles more Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi NVidia Microsoft Docker vpn