Показать сообщение отдельно
  #4 (permalink)  
Старый 23.02.2018, 18:58
Профессор
Отправить личное сообщение для Manyasha Посмотреть профиль Найти все сообщения от Manyasha
 
Регистрация: 21.09.2015
Сообщений: 196

wisma,
id должны быть уникальными
<form class="fn_variants preview_form" action="/cart">
   <button class="button buy fn_is_preorder hidden" type="submit" data-language="pre_order">Предзаказ</button>
   <button class="button buy fn_is_stock" type="submit"><span data-language="add_to_cart">В корзину</span></button>
   <select name="variant" class="fn_variant variant_select ">
      <option value="21" data-picture="http://s1.iconbird.com/ico/2013/8/428/w128h1281377930292cattied2.png"  data-price="2 899" data-stock="555" data-sku="wer">qwdqwdd</option>
      <option value="117" data-picture="http://s1.iconbird.com/ico/2013/8/428/w128h1281377930213catbox2.png"  data-price="2 899" data-stock="444" data-sku="ffff">цвет 2</option>
      <option value="118" data-picture="http://s1.iconbird.com/ico/2013/9/430/w128h1281378622418catlaptop.png"  data-price="2 899" data-stock="33" data-sku="вввыы">вввыыыы</option>
   </select>
   <div class="image-location" data-id="118"></div>
</form>

<form class="fn_variants preview_form" action="/cart">
   <button class="button buy fn_is_preorder hidden" type="submit" data-language="pre_order">Предзаказ</button>
   <button class="button buy fn_is_stock" type="submit"><span data-language="add_to_cart">В корзину</span></button>
   <select name="variant" class="fn_variant variant_select ">
      <option value="20" data-picture="http://s1.iconbird.com/ico/2013/8/428/w128h1281377930224catdrunk2.png"  data-price="2 899" data-stock="8" data-sku="123">цвет 32</option>
      <option value="119" data-picture="http://s1.iconbird.com/ico/2013/8/428/w128h1281377930234catfight2.png"  data-price="2 899" data-stock="44" data-sku="321">цвет 443</option>
      <option value="120" data-picture="http://s1.iconbird.com/ico/2013/9/430/w128h1281378622451catrascal.png"  data-price="2 899" data-stock="44" data-sku="431">цввет 34</option>
   </select>
   <div class="image-location" data-id="120"></div>
</form>

<script src="//code.jquery.com/jquery-1.9.1.min.js"></script>
<script>
$(".fn_variant.variant_select").change(function() { //if the select value gets changed
  var imageSource = $(this).find(':selected').data('picture'); //get the data from data-picture attribute
  if (imageSource) { //if it has data
    $(this).next().html('<img src=' + imageSource + '>'); // insert image in div image-location
  } else {
    $(this).next().html(''); //remove content from div image-location, thus removing the image
  }
})
</script>
Ответить с цитированием