<button class="draw-sector-button" data-sector_no="0">Draw first</button><section id="section-0"></section><button class="draw-sector-button" data-sector_no="1">Draw second</button><section id="section-1"></section>一個 HTML 頁面,有多個部分,每個部分都有按鈕。單擊按鈕觸發插件,然后填充相關的部分標簽。問題是,在插件回調中獲取標簽數據集,但“這個”指標不起作用:$('.draw-sector-button').myDrawPlugin({ // my data table generator param1 : 'foo', param2 : 'bar', onComplete : function(result) { var i = $(this).data('sector_no'); // (i : undefined) $('#section-'+i).html(result.data_table); }});他們說的是相反的:“您可以通過回調中的 this 關鍵字訪問實際的圖像節點?!?在JQuery 學習中心頁面中。所以我很困惑。任何人都可以提供解決方案嗎?
在插件函數中調用 html 數據集
青春有我
2021-08-20 19:02:50