jQuery change()Method

jQuery 事件方法jQuery Event Methods

Example

Alert text when the <input> field changes:

$("input").change(function(){
alert("Text has been modified");
});

Try it Yourself »

Definition and Usage

The change event occurs when the value of an element changes (only applicable to form fields).

The change() method triggers the change event, or specifies a function to run when the change event occurs.

Note:When used with select elements, the change event occurs when an option is selected. When used with text fields or text areas, the change event occurs when the element loses focus.


Syntax

Trigger the change event of the selected elements:

$(selector).change() Try it Yourself

Add a function to the change event:

$(selector).change(function) Try it Yourself

Parameter Description
function Optional. Specifies the function to run for the selected elements when the change event occurs.


jQuery 事件方法jQuery Event Methods

Other Extensions