Home > Web Front-end > JS Tutorial > jQuery's one() method usage example

jQuery's one() method usage example

巴扎黑
Release: 2017-06-25 11:12:04
Original
1185 people have browsed it

This article mainly introduces the usage of the one() method of jQuery. The example analyzes the function and definition of the one() method and binds a one-time to specific events of matching elements. Tips on using the event processing method. Friends who need it can refer to

. The example in this article describes the usage of jQuery's one() method. Share it with everyone for your reference. The specific analysis is as follows:

Bind a one-time event processing method to the specific event of the matching element.
The syntax of the one() method and the bind() method are the same. Their difference lies in the number of executions of the bound processing method.

Grammar structure:

The code is as follows:

$(selector).one(event,data,function)

parameter list:

Parameters Description
type Define the event type bound to the matching element.
If there are multiple events, separate them with spaces.
data Optional. Additional data objects passed to the event object.
function Defines a method that runs when an event occurs.

Example code:

The code is as follows:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="http://www.jb51.net/" />
<title>one()
函数
-脚本之家</title> 
<style type="text/css">
p{
  width:100px;
  height:100px;
  border:1px solid red
}
</style>
<script type="text/
javascript
" src="mytest/jQuery/jquery-1.8.3.js"></script>
<script type="text/javascript">
$(
document
).ready(function(){
  $("p").one("click",function(){
    $(this).append("添加的内容");
  })
})
</script>
</head>
<body>
  <p></p>
</body>
</html>
Copy after login

After clicking p, you can Adds the specified content, but this event handler will only be executed once.

The above is the detailed content of jQuery's one() method usage example. 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
Latest Issues
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template