js监听dom元素内容变化

//监听某个元素下新增元素事件

$("#photos").bind('DOMNodeInserted', function(e) {  

    alert('element now contains: ' + $(e.target).html());  

});  

//监听某个元素里移除元素的事件

$("#photos").bind('DOMNodeRemoved', function(e) {
  var num = 0;
  $("#photos li").each(function(){
  num += 1;
  });
});

猜你喜欢

转载自www.cnblogs.com/indifferent/p/12120277.html