change
UK[tʃeɪndʒ] US[tʃendʒ]
vt. Change, change; exchange, replacement; exchange; change clothes (sheets)
vi.Change, change; exchange, exchange; change clothes, change clothes
n.Change, change; exchange, alternation; change, change; substitute
jquery change() function syntax
Function:When the value of an element changes, a change event occurs. This event only applies to text fields, and textarea and select elements. The change() function triggers a change event, or specifies a function to run when a change event occurs. When used on a select element, 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.
Trigger change event: Trigger the change event of the selected element.
Syntax: $(selector).change()
Bind the function to the change event: Specifies when selected A function that runs when the element's change event occurs.
Syntax: $(selector).change(function)
Parameters:
Parameter | Description |
function | Optional. Specifies the function to run when the change event occurs. |
jquery change() function example
<html> <head> <script type="text/javascript" src="http://apps.bdimg.com/libs/jquery/2.1.1/jquery.min.js"></script> <script type="text/javascript"> $(document).ready(function(){ $(".field").change(function(){ $(this).css("background-color","#FFFFCC"); }); }); </script> </head> <body> <p>在某个域被使用或改变时,它会改变颜色。</p> Enter your name: <input class="field" type="text" /> <p>Car: <select class="field" name="cars"> <option value="volvo">Volvo</option> <option value="saab">Saab</option> <option value="fiat">Fiat</option> <option value="audi">Audi</option> </select> </p> </body> </html>
Click the "Run instance" button to view the online instance