简体   繁体   中英

jquery mobile - dynamically add toggle switch

Here is my Toggle Switch added dynamically

$('#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>')

My page have the event for change slider

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

but it does not work! can someone help me?

You need to use event delegation method, since they are created dynamically

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM