değiştirme fonksiyonu elemanlarına bağlayıcı değildir onlar kod yürütülmekte olan zamanda DOM bulunmayan çünkü; bunu çözebilir nasıl çalışır does't. Öğeleri DOM'a ve aynı anda ciltlemeye eklemek için bir işlev kullanabilirsiniz. Böyle
şey çalışacak:
function doStuff() {
$('#tr').html('<select class="optcode"><option>select code</option><option>select code</option></select>');
$('.optcode').change(function(){
alert('something');
})
}
$(document).ready(function() {
doStuff();
})
Bunu bu çalışma görebilirsiniz Fiddle JS: yardımcı https://jsfiddle.net/hsvnhhn7/
Umut.
$('#tr').html('<select class="optcode"><option>select code</option><option>select code</option></select>');
demo
$('#tr').html('<select class="optcode"><option>select code</option><option>select code</option></select>');
$('.optcode').change(function(){
alert('something');
})
<script src="https://ajax.googleapis.com/ajax/libs/jquery/2.1.1/jquery.min.js"></script>
<div id="tr"></div>
bkz
$('#tr').html('<select class="optcode">
<option>select code</option>
<option>select code</option>'
</select>);
İÇİN
$('#tr').on('change', '.optcode', function(){
alert('something');
});
yararlı oldu –