Home > Web Front-end > JS Tutorial > body text

jQuery: use case of live() method

黄舟
Release: 2017-06-26 09:17:40
Original
1171 people have browsed it

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)
Copy after login

Parameter list:

Parameters Description
type Defines one or more event types to attach to the element. Multiple event values ​​separated by spaces.
data Optional. Defines additional data passed to the event handling function.
function定义当事件发生时运行的函数。

实例代码:

<!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>
Copy after login

以上代码是为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!

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!