Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How jquery changes the value property

2025-04-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)05/31 Report--

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.

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 293

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report