jQuery val () method
Examples
Settings <input> field values:
$("button").click(function(){
$("input:text").val("Glenn Quagmire");
});
$("input:text").val("Glenn Quagmire");
});
try it"
Definition and Usage
val () method returns or sets the property value of the selected element.
When used for the return value:
This method returns the first element value matches the value of the property.
When used settings:
This method sets the value of all matched elements of value attributes.
Note: val () method is generally used with HTML form elements.
grammar
Returns the value property:
$(selector).val()
Set the value property:
$(selector).val(value)
Set the value property by function:
$(selector).val(function(index,currentvalue))
参数 | 描述 |
---|---|
value | 必需。规定 value 属性的值。 |
function(index,currentvalue) | 可选。规定返回要设置的值的函数。
|
More examples
Returns the value property
How to return value of the first matched element value attribute.
Use the function to set the property value
Use the function to set the value of the property value.