Home > Article > Web Front-end > jQuery: use case of live() method
This article mainly introduces the usage of the live() method in jQuery. The example analyzes the function and definition of the live() method, adds one or more events to matching elements, and stipulates when these events Friends who need tips on how to use the function when it occurs can refer to
This article explains the usage of the live() method in jQuery with examples. Share it with everyone for your reference. The specific analysis is as follows:
This method adds one or more events to the matching element and specifies the functions to be run when these events occur.
Special note: jQuery1.9 has deleted this method.
Grammar structure:
Copy code The code is as follows:
$(selector).live(type,data,function)
Parameter list:
实例代码:
<!DOCTYPE html> <html> <head> <meta charset="utf-8"> <meta name="author" content="http://www.jb51.net/" /> <title>脚本之家</title> <style type="text/css"> p{border:1px solid blue;} li{ list-style-type :none; width:150px; height:150px; border:1px solid green; } </style> <script type="text/ javascript " src="mytest/jQuery/jquery-1.8.3.js"></script> <script type="text/javascript"> $( document ).ready(function(){ $("p").live("click",function(){ $("li").slideToggle(); }) }) </script> </head> <body> <p> <ul> <li>点击这里测试一下</li> </ul> </p> </body> </html>
以上代码是为li元素注册click事件处理函数。
The above is the detailed content of jQuery: use case of live() method. For more information, please follow other related articles on the PHP Chinese website!