Home > Web Front-end > JS Tutorial > How to clear input value in jquery

How to clear input value in jquery

王林
Release: 2020-11-30 16:53:58
Original
6276 people have browsed it

Jquery method to clear input value: [$("#id").val("");]. The val() method returns or sets the value attribute of the selected element. When used to set a value, this method sets the value of the value attribute of all matching elements.

How to clear input value in jquery

The operating environment of this tutorial: Windows 7 system, jquery version 3.3.1. This method is suitable for all brands of computers.

jQuery method of clearing input values:

$("#id").val("");
Copy after login

(Learning video sharing: jquery video tutorial)

Method introduction:

The val() method returns or sets the value attribute of the selected element.

When used to return a value:

This method returns the value of the value attribute of the first matching element.

When used to set a value:

This method sets the value of the value attribute of all matching elements.

Note: The val() method is typically used with HTML form elements.

Example:

$("#id").val() //获取指定id元素的value属性的值
$("#id").val("") //设置指定id元素的value属性的值为空
$("#id").val("m.sbmmt.com") //设置指定id元素的value属性的值m.sbmmt.com
Copy after login

Related recommendations:js tutorial

The above is the detailed content of How to clear input value in jquery. For more information, please follow other related articles on the PHP Chinese website!

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