2013-04-28 71 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}); 
    }); 

如果我明白你要去的东西,无论如何...