2013-04-28 51 views
0

即時消息試圖做的是使用jQuery來獲取每個具有自己的唯一類的選定圖像的ID/CLASS(即image-1,image-2,等等),並讓jQuery顯示一個自定義值,我告訴它顯示在另一個div基於他們的選擇。jQuery/Magento - 獲取選定的div ID和顯示自定義值

到目前爲止,我有:

<div class="amconf-images-container" id="amconf-images-135"> 
<img id="amconf-image-66" src="media/amconf/images/66.jpg" class="amconf-image amconf-image-selected"> 
<img id="amconf-image-216" src="media/amconf/images/216.jpg" class="amconf-image"> 
<img id="amconf-image-218" src="media/amconf/images/218.jpg" class="amconf-image"> 
</div> 

,並試圖使用jQuery:

jQuery(function(){ 
var div = jQuery('.selectedimage')[0]; 
    jQuery("img#amconf-image-66.amconf-image amconf-image-selected").bind("change keyup", function(event){ 
    div.innerHTML = this.value = "Black"; 
}); }); 

多次讓每一個人可能的選擇。除非是更有效的方法來做到這一點,而不與magento的原型和自己的腳本相沖突?

謝謝!

回答

0

變化:

img#amconf-image-66.amconf-image amconf-image-selected 

要:

img#amconf-image-66.amconf-image.amconf-image-selected 
+0

似乎沒有工作:/無論用戶選擇什麼,該類從class =「amconf-image」更改爲class =「amconf-image aconf-image-selected」。任何方式來使jquery基於具有該類的圖像拉圖像?感謝您的答案btw。 – Gerardo 2013-04-28 21:37:41

0

將在頁腳的附加HTML節中引用的腳本文件下面,並設置數據的顏色在每個IMG標記在任何代碼生成它們:

jQuery(document).ready(function() { 
    jQuery('#amconf-img-container img').each(function() { 
     color = jQuery(this).data('color'); 
     jQuery(this).on('change keyup', function (event) { 
     if(jQuery(this).hasClass('selected')) { 
      div.innerHTML = event.data.color; 
     }}, {color: color}); 
    }); 

如果我明白你要去的東西,無論如何...