In jquery, the live() method is used to add event handlers to elements and specify the function to be run when the event occurs. The syntax is "$(selector).live(event,data,function to run)" "; This method was removed in jquery version 1.9 and can be replaced by the on() method.
The operating environment of this tutorial: windows10 system, jquery3.2.1 version, Dell G3 computer.
The live() method attaches one or more event handlers to the selected elements and specifies the functions to be run when these events occur.
Event handlers attached via the live() method apply to current and future elements matching the selector (such as new elements created by scripts).
Syntax
$(selector).live(event,data,function)
The parameters are expressed as follows:
event is required. Specifies one or more events to attach to the element. Multiple events separated by spaces. Must be a valid event.
data is optional. Specifies additional data to be passed to this function.
function required. Specifies a function to run when an event occurs.
The live() method is deprecated in jQuery version 1.7 and removed in version 1.9. Please use the on() method instead.
Examples are as follows:
<html> <head> <script type="text/javascript" src="/jquery/jquery.js"></script> <script type="text/javascript"> $(document).ready(function(){ $("button").live("click",function(){ $("p").slideToggle(); }); }); </script> </head> <body> <p>这是一个段落。</p> <button>请点击这里</button> </body> </html>
Recommended related video tutorials: jQuery video tutorial
The above is the detailed content of What is the usage of live in jquery. For more information, please follow other related articles on the PHP Chinese website!