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

jQuery's one() method usage example

PHPz
Release: 2018-09-29 16:37:02
Original
1278 people have browsed it

This article mainly introduces the usage of jQuery's one() method. The example analyzes the function and definition of the one() method and the usage skills of binding a one-time event processing method for specific events of matching elements. Friends who need it For reference, the specific analysis is as follows:

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

Syntax structure:

$(selector).one(event,data,function)
Copy after login

Parameter list:

Parameters
参数描述
type定义绑定到匹配元素中的事件类型。
如果有多个事件使用空格分隔。
data可选。传递给事件对象的额外数据对象。
function定义当事件发生时运行的方法。
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<🎜>Define a method to run when the event occurs. <🎜>

实例代码:

<!DOCTYPE html>
<html>
<head>
<meta charset=" utf-8">
<meta name="author" content="//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

点击p之后,可以为p添加指定的内容,但是此事件处理函数只会被执行一次。

以上就是本章的全部内容,更多相关教程请访问jQuery视频教程

Related labels:
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