按钮在第一次成功的 ajax 数据加载后不起作用

Button is not working after first successful ajax data laod

本文关键字:数据 加载 不起作用 ajax 第一次 成功 按钮      更新时间:2023-09-26
var Update = {
	    init: function(){
	    	 $('.find').on('click', function(e){
	             e.preventDefault();
	             var
	             $this = $(this),
	             $form = $('#searchForm');
	             BLC.ajax({
	            	 url: "/emp/find",
	                 type: 'POST',
	                 data: data
	             },function(data){	                               
	                 $('#findEmployees').html(data);
	             });
	         });
	    }
	};
<div id="findEmployees">
	<blc:form method="POST" th:action="@{/emp/find" id="searchForm">
		<input type="text" th:field="*{employee.id}" name="id" id="id" />
		<button id="find" name="find" class="find" type="button"
			th:text="Find"></button>
	</blc:form>
	<blc:form class="detailform" name="detailform"
		th:action="@{/emp/deatils}" method="post">
		<input type="hidden" th:id="id" th:name="id" th:value="*{id}" />
		<a href="#" class="empLink">
			<h4 th:text="*{id}"></h4>
		</a>
	</blc:form>
</div>

因为您要将div 中的内容替换为 Ajax 调用中的新内容,所以需要引用文档并将事件处理程序委托给新添加的代码。

 $(document).on('click', '.find', function(e){....