How to add click and double-click events to an element through jQuery

藏色散人
Release: 2021-08-27 11:09:30
Original
2440 people have browsed it

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:

        

PHP中文网

如何给一个元素添加单击和双击事件?

可点击的元素
Copy after login

The effect is as follows:

GIF 2021-8-27 星期五 上午 10-58-23.gif

  • ##bind() syntax is

    $(selector).bind(event,data,function,map)

  • 参数分别表示: event必需。规定添加到元素的一个或多个事件。 由空格分隔多个事件值。必须是有效的事件。 data可选。规定传递到函数的额外数据。 function必需。规定当事件发生时运行的函数。 map规定事件映射 ({event:function, event:function, ...}),包含要添加到元素的一个或多个事件,以及当事件发生时运行的函数。
    Copy after login
  • appendTo() syntax is

    $(content) .appendTo(selector)

    ##
    参数分别表示: content必需。规定要插入的内容(可包含 HTML 标签)。 selector必需。规定把内容追加到哪个元素上。
    Copy after login
    Note:

    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!

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
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!