在这个脚本中,我如何添加一个alt
标签,该标签的值将与本例中的"NikeAir 32"相同?
<script>
function test_options_rendered(){
$('.test_option_value').each(function(){
if( !$(this).parent().hasClass("conditional")){
$(this).find('input:radio').first().prop("checked", true);
// $(".test_radio_option :input:first").prop("checked", true);
}
});
$('.test_radio_option:contains("Nike Air32")').append('<img class="option_img" src="https://image.png">');
}
</script>
如果您想要做的是将alt
标签添加到img
中,您可以这样做:
$('.test_radio_option:contains("Nike Air32")')
.append('<img class="option_img" alt="Nike Air32" src="https://image.png">')
如果你想让它更动态,你可以这样做:
$('.test_radio_option:contains("Nike Air32")').each(function() {
$(this).append('<img class="option_img" alt="' + $(this).text() + '" src="https://image.png">');
});