In the previous article "Use JavaScript to delete the last item from the array (3 methods)", I introduced you how to use JavaScript to delete the last item from the array. Interested friends can Go learn and understand~
The important content explained in this article is the method of adding click and double-click events to elements through jQuery.
In this article we will add click and double-click events through thebind()
method. The bind() method adds one or more event handlers to the selected element, as well as a function to run when the event occurs. In addition, we will add the result to the element using the appendTo() method, which inserts the specified content at the end (still inside) of the selected element.
Let’s go directly to the code:
The effect is as follows:
$(selector).bind(event,data,function,map)
参数分别表示: event必需。规定添加到元素的一个或多个事件。 由空格分隔多个事件值。必须是有效的事件。 data可选。规定传递到函数的额外数据。 function必需。规定当事件发生时运行的函数。 map规定事件映射 ({event:function, event:function, ...}),包含要添加到元素的一个或多个事件,以及当事件发生时运行的函数。
$(content) .appendTo(selector)
参数分别表示: content必需。规定要插入的内容(可包含 HTML 标签)。 selector必需。规定把内容追加到哪个元素上。
Since jQuery version 1.7, the on() method adds event handling to the selected element The preferred method of the program.
The append() and appendTo() methods perform the same task; the differences are: the positioning of the content and selector, and the ability of append() to use functions to append content.
Finally, I would like to recommend "
JavaScript Basics Tutorial" ~ Welcome everyone to learn ~
The above is the detailed content of How to add click and double-click events to an element through jQuery. For more information, please follow other related articles on the PHP Chinese website!