$('#selectSurvey').append('<option value="1" data-img="/path/image.png">'+ Option1 +'</option>');
$('#selectSurvey').on('change',function(e){
$('#image-here').attr('src',this.data('img')); //wrong
});
如何在更改下拉列表中的Option1中获取数据?
尝试option
从select元素中获取所选内容,然后检索数据,
$('#selectSurvey').on('change',function(e){
$('#image-here').attr('src',$(this).find('option:selected').data('img'));
});
由于data-img
已使用option
元素而不是使用设置了select
。
本文收集自互联网,转载请注明来源。
如有侵权,请联系[email protected] 删除。
我来说两句