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>
    <script src="../jquery-3.3.1.min.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    <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>
    </html>
    

    二、挂事件

    <!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>
    <script src="../jquery-3.3.1.min.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    
    
        <input  type="button" class="cc" value="挂事件" id="a"/>
        <input  type="button" class="cc" value="测试事件" id="b"/>
        <input  type="button" class="cc" value="移除事件" id="c"/>
        
    </body>
    <script type="text/javascript">
        var a = $("#aa");
        var b = $(".bb");
        var c = $(".cc");
        $("#a").click(function(){
            $("#b").bind("click",function(){
                alert("测试事件");
            }) 
        })//挂事件
    </script>
    </html>
    

    显示:

    三 移除事件

    <!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>
    <script src="../jquery-3.3.1.min.js"></script>
    <meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
    <title>无标题文档</title>
    </head>
    <body>
        <input  type="button" class="cc" value="挂事件" id="a"/>
        <input  type="button" class="cc" value="测试事件" id="b"/>
        <input  type="button" class="cc" value="移除事件" id="c"/>
      
    </body>
    <script type="text/javascript">
        $("#a").click(function(){
            $("#b").bind("click",function(){
                alert("测试实验");
            });
        });//挂事件
        $("#c").click(function(){
            $("#b").unbind("click");   
        });//移除事件
    </script>
    </html>
  • 相关阅读:
    Hadoop-2.4.1学习之Map任务源代码分析(下)
    微软面试题之两个链表的第一个公共结点
    再次轻度破解EXE文件
    源泉书签,助您管理海量收藏。www.yuanquanshuqian.com,今日更新:多标签功能已实现
    经验总结17--submitbutton,ajax提交
    python学习笔记(六)文件夹遍历,异常处理
    vue 数据传递的方法
    Vue 组件之间的数据传递
    Springboot文件下载
    springboot获取URL请求参数的几种方法
  • 原文地址:https://www.cnblogs.com/xiaohaihuaihuai/p/8360075.html
Copyright © 2011-2022 走看看