.on无法使用动态html [英] .on not working on dynamic html

查看:56
本文介绍了.on无法使用动态html的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在创建拖放的东西.发生拖放操作时,我将创建新的运行时html并希望绑定该事件,因此我使用了 .on

I am creating drag and drop thing. When drop happens I create new runtime html and want to bind it event, so I have used following .on

 .on ( "event", "selector", function() {

,但不起作用.这是代码段:

but its not working. Here is Snippet :

$( "#wrap .dragImages" ).on( "click", "button.edit-new-modal", function() {
    var photoId = $(this).attr('data-username');        
    alert(photoId);
});

.on 可以在拖放之前工作.但是,点击"button.edit-new-modal"后,什么也没发生!!怎么了?有解决办法吗?

.on works before drag and drop. But afterwords nothing happens on clicking "button.edit-new-modal"!! What's wrong? Any solution?

推荐答案

尝试:

$(document.body).on( "click", "button.edit-new-modal", function() {
  var photoId = $(this).attr('data-username');        
  alert(photoId);
});

这篇关于.on无法使用动态html的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆