Home > Article > Web Front-end > jQuery's one() method usage example
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:
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>
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!