簡體   English   中英

jQuery mobile-動態添加切換開關

[英]jquery mobile - dynamically add toggle switch

這是我動態添加的撥動開關

$('#item').append('<div data-role="fieldcontain"><label for="flip">Status : </label><select class="flip" name="slider" id="flip1" data-role="slider"><option value="false" selected="selected">Off</option><option value="true">On</option></select></div>')

我的頁面具有更改事件滑塊

$("#flip1").on("slidestart", function(event, ui) {
    alert('test');
});

但它不起作用! 有人能幫我嗎?

您需要使用event delegation方法,因為它們是動態創建的

$('#item').on("slidestart","#flip1", function(event, ui) {
    alert('test');
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM