【发布时间】:2013-11-19 22:31:40
【问题描述】:
我正在尝试使用 2 组单选按钮分组更改为 2 组不同的图像。如果只存在一组单选按钮,我的代码将更改一组图像。当我添加第二组单选按钮时,两组单选按钮仅更改 1 个图像组。对不起,如果我没有意义。
广播组 1
<input type="radio" name="barrel" class="color-picker" id="Black" value="Black" />
<input type="radio" name="barrel" class="color-picker" id="Carolina_Blue" value="Carolina_Blue" />
<input type="radio" name="barrel" class="color-picker" id="Charcoal" value="Charcoal" />
广播组 2
<input type="radio" name="handle" class="color-picker" id="Black" value="Black" />
<input type="radio" name="handle" class="color-picker" id="Carolina_Blue" value="Carolina_Blue" />
<input type="radio" name="handle" class="color-picker" id="Charcoal" value="Charcoal" />
这是第 1 组的 jQuery
jQuery('input:radio[name="barrel"]').change(function(){
if ($(this).prop("checked") && $(this).val() == 'Black'){
jQuery('.barrel').css({'background-image':'url("http://www.nationalbatcompany.com/wp-content/themes/nationalbat/images/bats/barrels/black-barrel.png")'});
jQuery('.customize-image .bat-text').css({'color':'#ffffff'});
}
else if ($(this).prop("checked") && $(this).val() == 'Carolina_Blue'){
jQuery('.barrel').css({'background-image':'url("http://www.nationalbatcompany.com/wp-content/themes/nationalbat/images/bats/barrels/carolina-blue-barrel.png")'});
jQuery('.customize-image .bat-text').css({'color':'#130F06'});
}
else if ($(this).prop("checked") && $(this).val() == 'Charcoal'){
jQuery('.barrel').css({'background-image':'url("http://www.nationalbatcompany.com/wp-content/themes/nationalbat/images/bats/barrels/charcoal-barrel.png")'});
jQuery('.customize-image .bat-text').css({'color':'#ffffff'});
}
});
这是第 2 组的 jQuery
jQuery('input:radio[name="handle"]').change(function(){
if ($(this).prop("checked") && $(this).val() == 'Black'){
jQuery('.handle').css({'background-image':'url("http://www.nationalbatcompany.com/wp-content/themes/nationalbat/images/bats/handles/black-handle.png")'});
}
else if ($(this).prop("checked") && $(this).val() == 'Carolina_Blue'){
jQuery('.handle').css({'background-image':'url("http://www.nationalbatcompany.com/wp-content/themes/nationalbat/images/bats/handles/carolina-blue-handle.png")'});
}
else if ($(this).prop("checked") && $(this).val() == 'Charcoal'){
jQuery('.handle').css({'background-image':'url("http://www.nationalbatcompany.com/wp-content/themes/nationalbat/images/bats/handles/charcoal-handle.png")'});
}
});
这是该网站的链接:http://www.nationalbatcompany.com/products/t-ball-bat/
如果您点击自定义您的球棒,您将看到枪管和手柄颜色。如果您单击桶样本颜色,桶图像将会改变,如果您点击手柄颜色,桶颜色也会改变。这不是预期的功能。单击手柄图像样本时,手柄颜色应更改
任何帮助将不胜感激。
【问题讨论】:
-
你可以做一个小提琴jsfiddle.net,而不是链接到该网站