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

How to clear input value in jquery

王林
王林Original
2020-11-19 09:35:356214browse

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("");

(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("www.php.cn") //设置指定id元素的value属性的值www.php.cn

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!

Statement:
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