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

How to bind click event in jquery

王林
王林Original
2020-11-26 09:17:237064browse

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)

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>

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!

Statement:
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