简体   繁体   中英

how to check checkbox event dynamically created in javascript using jquery mobile

Here I am getting values from sqlite db,binding those values in javascript and showing it on html by calling id of that particular .In this process I reuired to put checkbox.I created it in javascript only not in html. so now i required to check the checkbox in dynamically created javascript. here I am pasting my code. Thanks in advance for your valuable suggestions.

$('#lightsList').append('<li style="background:#666666">'+
            '<img src="../images/' + light.ledLightImage + '" class="ui-li-thumb" style="margin-left: 10px; margin-top:2px;"/>' +
            '<form id="checkbox" style="padding-top:18px; color:#ffffff">'+
            '<input type="checkbox" name="Tick" value="Tick" class="regular-checkbox" onclick="checked()"/><br>Tick'+
            '</form>' +
            '<p class="line1">' + light.ledLightName  + '</p>' +
            '</li>'+
            '<li style="display:none;">'+light.ledWattage+'</li>');

You need to use on() for event delegation like,

$('#lightsList').on('click', '.regular-checkbox', function() {
    checked();// call your function checked here
});

Try this:

$(document).on('change', '.regular-checkbox', function() {
    // event handler
});

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