Javascript 自动命名一个alt标记

Javascript 自动命名一个alt标记,javascript,jquery,Javascript,Jquery,在本脚本中,我如何添加一个alt标记,该标记的值与本例中的“NikeAir 32”相同 <script> function test_options_rendered(){ $('.test_option_value').each(function(){ if( !$(this).parent().hasClass("conditional")){ $(this).find('input:radio').first()

在本脚本中,我如何添加一个
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>

功能测试\u选项\u呈现(){
$('.test_option_value')。每个(函数(){
if(!$(this.parent().hasClass(“条件”)){
$(this.find('input:radio').first().prop(“checked”,true);
//$(“.test\u radio\u选项:输入:first”).prop(“选中”,true);
}
});
$('.test_radio_选项:包含(“Nike Air32”))。附加('');
}

如果您只想在
img
中添加一个
alt
标记,您可以这样做:

$('.test_radio_option:contains("Nike Air32")')
   .append('<img class="option_img" alt="Nike Air32" src="https://image.png">')
$('.test_radio_选项:包含(“Nike Air32”))
.append(“”)
如果要更动态地执行此操作,可以执行以下操作:

$('.test_radio_option:contains("Nike Air32")').each(function() {
    $(this).append('<img class="option_img" alt="' + $(this).text() + '" src="https://image.png">');
});
$('.test_radio_选项:包含(“Nike Air32”))。每个(函数(){
$(此)。附加(“”);
});

你的问题和来源对我来说毫无意义。你试过做什么?你会做
$('.test\u radio\u option:contains(“Nike Air32”))。append('')