zoukankan      html  css  js  c++  java
  • jQuery事件

    一、添加单击事件

    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml">
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    <script src="../jquery-3.3.1.min.js"></script><!--如果有多个js
    样式把jquery放在最上面防止出错-->
    </head>

    <body>
    <body>
        <input  type="button" class="cc" value="ff"/>
        <input  type="button" class="cc" value="gg"/>
        <input  type="button" class="cc" value="ii"/>
        <input  type="button" name="cc" value="jj"/>
    </body>
    <script type="text/javascript">
        var a = $("#aa");
        var b = $(".bb");
        var c = $(".cc");
        $("[name='cc']").click(function(){
            alert("nihao");    //单个添加单击事件
        })
        $(".cc").on("click",function(){
            alert($(this).val());//谁触发。this就代表谁
                
        })//多个元素单击加事件
    </script>
    </body>

    二、挂事件

    <body>
        <input  type="button" class="cc" value="ff" id="a"/>
        <input  type="button" class="cc" value="gg" id="b"/>
        <input  type="button" class="cc" value="ii" id="c"/>
        <input  type="button" name="cc" value="jj"/>
    </body>
    <script type="text/javascript">
    	var a = $("#aa");
    	var b = $(".bb");
    	var c = $(".cc");
    	$("#a").click(function(){
    		$("#b").bind("click",function(){
    			alert("shenme");
    		})	
    	})//挂事件
    </script>
    

     

    三、移除事件

    <body>
        <input  type="button" class="cc" value="ff" id="a"/>
        <input  type="button" class="cc" value="gg" id="b"/>
        <input  type="button" class="cc" value="ii" id="c"/>
        <input  type="button" name="cc" value="jj"/>
    </body>
    <script type="text/javascript">
    	var a = $("#aa");
    	var b = $(".bb");
    	var c = $(".cc");
    	$("#a").click(function(){
    		$("#b").bind("click",function(){
    			alert("shenme");
    		});	
    	});//挂事件
    	$("#c").click(function(){
    		$("#b").unbind("click");	
    	});//移除事件
    </script>
    
  • 相关阅读:
    a gcc 4.2.4 bug(被stos指令累加后%edi作为参数的)
    gcc -02引起内存溢出'unsigned i'应修订为'volatile unsigned i'
    gcc优化引起get_free_page比__get_free_page返回值多4096
    gcc请不要优化
    change_bit 按位取反
    IBM messed up *AGAIN* in their thinkpad: 0xA0000 -> 0x9F000
    python正则实例
    详解volatile 关键字与内存可见性
    并发基础知识
    Spring通过注释配置Bean2 关联关系
  • 原文地址:https://www.cnblogs.com/navyouth/p/8340265.html
Copyright © 2011-2022 走看看