jQuery form event change() event
change event (change event)
Definition and usage
The change event occurs when the value of an element changes.
This event only applies to text fields, textarea and select elements.
change() function triggers a change event, or specifies a function to run when a change event occurs.
Note: When used with select elements, the change event occurs when an option is selected. When used with a text field or text area, this event occurs when the element loses focus.
Let’s write an example below
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <title></title> <script src="http://libs.baidu.com/jquery/1.9.1/jquery.js"></script> </head> <body> <select> <option>安徽</option> <option>上海</option> <option>北京</option> </select> <p>php 中文网</p> <script> $('select').change(function(){ $('p').css('color','red'); }) </script> </body> </html>
When the value in the drop-down option box changes, the color of the text in the p tag will change