Home > Web Front-end > JS Tutorial > How to bind click event in jquery

How to bind click event in jquery

王林
Release: 2020-11-30 10:44:29
Original
7117 people have browsed it

Jquery binding click event method: [$("#text").bind("click",function(){});]. The bind method adds one or more event handlers to the selected element and specifies the function to run when the event occurs.

How to bind click event in jquery

The operating environment of this tutorial: Windows 10 system, jquery version 2.2.4. This method is suitable for all brands of computers.

(Learning video sharing: jquery video tutorial)

Function introduction:

bind() method adds one or more events to the selected element handler and specifies a function to run when an event occurs.

Syntax:

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

Parameters:

  • ##event Required. Specifies one or more events to be added to the element. Multiple events separated by spaces. Must be a valid event.

  • data Optional. Specifies additional data to be passed to the function.​

  • #function Required. Specifies a function to run when an event occurs.

Part of the implementation code of jquery dynamically binding click events is as follows:


<script type="text/javascript">
$(document).ready(function(){
    $("#text").bind("click",function(){
        alert("我的id为text,你点击时触发");
    });
    
    $("#text1").on("click",function(){
        alert("hellworl");
    });
    
    $("#text2").click(function(){
        alert($("#text2").val());
        
    });
});
    
    
</script>
<body>
    
    <input id="text" type="button" value="点击"/> 
    
    <input id="text1" type="button" value="点击"/> 
    
    <input id="text2" type="text" value="love"/> 
</body>
Copy after login
Related recommendations:

js tutorial

The above is the detailed content of How to bind click event in 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 Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template