[英]Event delegation after removing class
我有一個按鈕
<button data-button='next' class="disabled">next</button>
我刪除了禁用的類來激活,但事件不起作用
$("[data-button='next']:not(.disabled)").on('click', document, function(){
我怎樣才能使這個工作
哪個不是事件委派的正確語法,請按如下方式更新。
// provide any selector which is parent of the dynamic element
//--\/-- and present when handler is attaching
$(document).on('click', "[data-button='next']:not(.disabled)", function(){
// --------------------^^^^^---- provide the selector of corresponding dynamic element
// code here
});
$(document).on('click', "[data-button='next']:not(.disabled)", function() { console.log('clicked'); }); $("[data-button='next']").removeClass('disabled')
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script> <button data-button='next' class="disabled">next</button>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.