私信  •  关注

Ankit Kathiriya

Ankit Kathiriya 最近创建的主题
Ankit Kathiriya 最近回复了
9 年前
回复了 Ankit Kathiriya 创建的主题 » jquery函数不使用Ajax返回/呈现的页面[重复]

任何P 那不存在吗 在绑定事件时,如果您的页面是 动态创建元素 具有类名 按钮 将事件绑定到已存在的父级

$(document).ready(function(){
  //Particular Parent chield click
  $(".buttons").on("click","button",function(){
    alert("Clicked");
  });  
  
  //Dynamic event bind on button class  
  $(document).on("click",".button",function(){
    alert("Dymamic Clicked");
  });
  $("input").addClass("button");  
});
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.1/jquery.min.js"></script>
<div class="buttons">
  <input type="button" value="1">
  <button>2</button>
  <input type="text">
  <button>3</button>  
  <input type="button" value="5">  
  </div>
<button>6</button>