• 为动态添加的元素绑定事件


    <!DOCTYPE html>
    <html>
    <head>
    <script src="/jquery/jquery-1.11.1.min.js">
    </script>
    <script>
    $(document).ready(function(){
      $("body").on('click','p',function(){
        $(this).hide();
      });
    });
    </script>
    </head>
    <body>
    <p>如果您点击我,我会消失。</p>
    <p>点击我,我会消失。</p>
    <p>也要点击我哦。</p>
    </body>
    </html>
    <!DOCTYPE html>
    <html>
    <head>
    <script src="/jquery/jquery-1.11.1.min.js">
    </script>
    <script>
    $(document).ready(function(){
      $("p").click(function(){
        $(this).hide();
      });
    });
    </script>
    </head>
    <body>
    <p>如果您点击我,我会消失。</p>
    <p>点击我,我会消失。</p>
    <p>也要点击我哦。</p>
    </body>
    </html>

    注意1,2代码区别,方式1,后期动态添加的<p>标签是可以点击消失的,方式2不行

  • 相关阅读:
    POJ3666 Making the Grade[动态规划]
    vector内部的实现1
    win32概述
    stl概述
    C++概要简介
    类的常量成员
    模板
    c11标准
    异常处理
    pak文件的打包和解包
  • 原文地址:https://www.cnblogs.com/zhaogaojian/p/12326004.html
Copyright © 2020-2023  润新知