有人可以幫助我嗎?這是我的問題。當我嘗試單擊button使用此功能時$(".btn_cellophane").on("click",function(){});,我沒有得到任何響應,甚至沒有得到錯誤。我猜這個onclick功能不起作用。下面是我的代碼。方法調用$(".btn_cellophane").on("click",function(){ alert("Tester true"); if($(this).hasClass("btn-warning")){ $(this).removeClass("btn-warning"); $(this).addClass("btn-success"); // add_amount_for_cellophane(); }else if($(this).hasClass("btn-success")){ $(this).addClass("btn-warning"); $(this).removeClass("btn-success"); // add_amount_for_cellophane(); }});內容展示var html_cellophane = "";$.each(data, function(key,product){ $.each(product.sizes, function(pro_id,variant){ if(variant.prod_type == 1){ var label = (variant.size+" "+variant.unit).toUpperCase(); var var_id = variant.variant_id; var price = variant.price; html_cellophane += '<div>'+ '<label>Cellophane ('+price+' pesos)</label>'+ '</div>'+ '<br/>'+ } }); });
1 回答

縹緲止盈
TA貢獻2041條經驗 獲得超4個贊
您已經動態創建了該按鈕。因此,當您附加事件偵聽器時,該元素在此之前并不存在。因此,您必須使用事件委托來處理單擊事件。
只需像這樣更改您的事件偵聽器 -
$(document).on("click",".btn_cellophane",?function(){});
- 1 回答
- 0 關注
- 99 瀏覽
添加回答
舉報
0/150
提交
取消