Home > Article > Web Front-end > How to clear input value in jquery
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.
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!