2016-08-29 60 views
-2

在这个脚本中,我该如何添加一个alt标记,其值与本例中的“NikeAir 32”相同?自动命名alt标记

<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> 
+0

你的问题和来源对我没有任何意义。你有什么想要做的? – eisbehr

+0

你会做'$('。test_radio_option:contains(“Nike Air32”)')。append('Nike Air32');' –

回答

0

如果你想要做的就是添加一个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">'); 
});