zoukankan      html  css  js  c++  java
  • Flask ajax 动态html 的javascript 事件失效

    $('.db_edit').click(function(){
                $(".editdbproduct").val($(this).parent().parent().find('.editdb_product').text());
                $('.editdbserver').val($(this).parent().parent().find('.editdb_host').text());
                $('.editdbname').val($(this).parent().parent().find('.editdb_instance').text());
                $('.editschema').val($(this).parent().parent().find('.editdb_schemas').text());
                $('.editdbdesc').val($(this).parent().parent().find('.editdb_desc').text());
                orginaldb = $('.editdbname').val();
    });

    修改后:

    $("body").delegate(".db_edit","click", function(){
                $(".editdbproduct").val($(this).parent().parent().find('.editdb_product').text());
                $('.editdbserver').val($(this).parent().parent().find('.editdb_host').text());
                $('.editdbname').val($(this).parent().parent().find('.editdb_instance').text());
                $('.editschema').val($(this).parent().parent().find('.editdb_schemas').text());
                $('.editdbdesc').val($(this).parent().parent().find('.editdb_desc').text());
                orginaldb = $('.editdbname').val();
    
           });

    原因: 是因为这些动态加载的这些HTML页面(图二),是在列表数据页面(图一)的HTML元素,css,js代码加载完后,再添加的HTML元素,

    在浏览器解析到图一的页面元素时, 解析到js的这些绑定标签事件的js代码(上面的JS代码)的时候,这些绑定事件的标签元素还没有生成,

    (因为js代码加载完后,才会有这些绑定事件的标签),所以这些JS 代码的绑定的事件,根本就没有绑定到这些动态加载的标签上,所以哪些事件不会触发。

    reference: https://www.cnblogs.com/heganlin/p/5848833.html

  • 相关阅读:
    Django Rest framework基础使用之Request/Response
    Django Rest framework基础使用之 serializer
    python基础(一)
    python实现本地图片上传到服务区
    开发中遇到的问题记录
    九、xadmin菜单分组管理
    leetcode-7-整数翻转
    leetcode-6-Z 字形变换
    leetcode-5-最长回文子串
    leetcode-3-无重复字符的最长子串
  • 原文地址:https://www.cnblogs.com/kiddy/p/9818144.html
Copyright © 2011-2022 走看看