jquery live() method
Translation results:
live
英[lɪv] 美[lɪv]
vi.live; survive; live; live; enjoy in life
vt.Experience; spend time
adj.live;vivid,spiritual;energetic;live broadcast
adv.at (performance) scene, lively
jquery live() methodsyntax
Function:The live() method attaches one or more event handlers to the selected element and specifies the functions to be run when these events occur. Event handlers attached via the live() method apply to the current and future elements that match the selector (such as new elements created by a script).
Syntax: $(selector).live(event,data,function)
Parameters:
Parameters | Description |
event | Required. Specifies one or more events to attach to the element. Multiple events separated by spaces. Must be a valid event. |
data | Optional. Specifies additional data to be passed to this function. |
function | Required. Specifies a function to run when an event occurs. |
jquery live() methodexample
<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(){ $("button").live("click",function(){ $("p").slideToggle(); }); }); </script> </head> <body> <p>这是一个段落。</p> <button>请点击这里</button> </body> </html>
Click the "Run instance" button to view the online instance