Home >Web Front-end >JS Tutorial >jQuery's one() method usage example
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)
Parameter list:
实例代码:
<!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>
点击p之后,可以为p添加指定的内容,但是此事件处理函数只会被执行一次。
以上就是本章的全部内容,更多相关教程请访问jQuery视频教程!