我想去年我问了这个问题,但我没有做好准备,我的问题表达得也没有我想象的那么好。不管怎样,我有很多人愿意帮忙,我非常感激。这一次,我制作了一把小提琴,希望能让你们更好地帮助我。https://jsfiddle.net/jasonbruce/qwuojxg0/28/
如果需要,这是整页-https://www.sanjosecoder.com/porsche-working/index.html -所有代码都在页面本身上。
我正在制作一个模拟汽车选择器页面来帮助我学习javascript,并希望用户能够选择汽车颜色,然后选择车轮样式。在车轮样式中循环时,应保持车辆颜色,反之亦然。我希望用户能够选择控制盘样式,然后在保持选定控制盘样式的同时循环颜色,或者选择绘制颜色,然后循环控制盘。
目前,您可以在五种不同的轮子类型或十六种不同的颜色之间进行选择,但彼此独立,而我无法想出javascript逻辑将它们联系在一起。
我有所有16种颜色的所有5种车轮样式的独特图片,总共有80张图片。
我考虑/尝试过的事情。。。
创建包含所有80个映像路径的数组,并调用相应的路径
在html中创建80个图像标记以在dom中获取它们,将图像类设置为display:none;然后设置显示:块;onclick
我没能和我的新保姆产生逻辑,我被卡住了。下面是我目前使用的一些逻辑。
function color1() {
document.getElementById("carerra").src = 'images/carerra-s/color1-option1.png';
document.getElementById("exterior-swatch1").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color1-checked.png");';
document.getElementById("exterior-swatch2").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color2.png");';
document.getElementById("exterior-swatch3").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color3.png");';
document.getElementById("exterior-swatch4").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color4.png");';
document.getElementById("exterior-swatch5").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color5.png");';
document.getElementById("exterior-swatch6").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color6.png");';
document.getElementById("exterior-swatch7").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color7.png");';
document.getElementById("exterior-swatch8").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color8.png");';
document.getElementById("exterior-swatch9").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color9.png");';
document.getElementById("exterior-swatch10").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color10.png");';
document.getElementById("exterior-swatch11").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color11.png");';
document.getElementById("exterior-swatch12").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color12.png");';
document.getElementById("exterior-swatch13").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color13.png");';
document.getElementById("exterior-swatch14").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color14.png");';
document.getElementById("exterior-swatch15").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color15.png");';
document.getElementById("exterior-swatch16").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color16.png");';
}
<!-- - - - - - - - - - - - - - - - - - CAR COLOR 2 - WHITE - - - - - - - - - - - - - - - - - -->
function color2() {
document.getElementById("carerra").src = 'https://www.sanjosecoder.com/porsche-working/images/carerra-s/color2-option1.png';
document.getElementById("exterior-swatch2").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color2-checked.png");';
document.getElementById("exterior-swatch1").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color1.png");';
document.getElementById("exterior-swatch3").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color3.png");';
document.getElementById("exterior-swatch4").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color4.png");';
document.getElementById("exterior-swatch5").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color5.png");';
document.getElementById("exterior-swatch6").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color6.png");';
document.getElementById("exterior-swatch7").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color7.png");';
document.getElementById("exterior-swatch8").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color8.png");';
document.getElementById("exterior-swatch9").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color9.png");';
document.getElementById("exterior-swatch10").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color10.png");';
document.getElementById("exterior-swatch11").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color11.png");';
document.getElementById("exterior-swatch12").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color12.png");';
document.getElementById("exterior-swatch13").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color13.png");';
document.getElementById("exterior-swatch14").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color14.png");';
document.getElementById("exterior-swatch15").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color15.png");';
document.getElementById("exterior-swatch16").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color16.png");';
}
<!-- - - - - - - - - - - - - - - - - - CAR COLOR 3 - YELLOW - - - - - - - - - - - - - - - - - -->
function color3() {
document.getElementById("carerra").src = 'https://www.sanjosecoder.com/porsche-working/images/carerra-s/color3-option1.png';
document.getElementById("exterior-swatch3").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color3-checked.png");';
document.getElementById("exterior-swatch1").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color1.png");';
document.getElementById("exterior-swatch2").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color2.png");';
document.getElementById("exterior-swatch4").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color4.png");';
document.getElementById("exterior-swatch5").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color5.png");';
document.getElementById("exterior-swatch6").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color6.png");';
document.getElementById("exterior-swatch7").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color7.png");';
document.getElementById("exterior-swatch8").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color8.png");';
document.getElementById("exterior-swatch9").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color9.png");';
document.getElementById("exterior-swatch10").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color10.png");';
document.getElementById("exterior-swatch11").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color11.png");';
document.getElementById("exterior-swatch12").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color12.png");';
document.getElementById("exterior-swatch13").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color13.png");';
document.getElementById("exterior-swatch14").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color14.png");';
document.getElementById("exterior-swatch15").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color15.png");';
document.getElementById("exterior-swatch16").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color16.png");';
}
<!-- - - - - - - - - - - - - - - - - - CAR COLOR 4 - RED - - - - - - - - - - - - - - - - - -->
function color4() {
document.getElementById("carerra").src = 'https://www.sanjosecoder.com/porsche-working/images/carerra-s/color4-option1.png';
document.getElementById("exterior-swatch4").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color4-checked.png");';
document.getElementById("exterior-swatch1").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color1.png");';
document.getElementById("exterior-swatch2").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color2.png");';
document.getElementById("exterior-swatch3").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color3.png");';
document.getElementById("exterior-swatch5").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color5.png");';
document.getElementById("exterior-swatch6").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color6.png");';
document.getElementById("exterior-swatch7").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color7.png");';
document.getElementById("exterior-swatch8").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color8.png");';
document.getElementById("exterior-swatch9").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color9.png");';
document.getElementById("exterior-swatch10").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color10.png");';
document.getElementById("exterior-swatch11").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color11.png");';
document.getElementById("exterior-swatch12").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color12.png");';
document.getElementById("exterior-swatch13").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color13.png");';
document.getElementById("exterior-swatch14").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color14.png");';
document.getElementById("exterior-swatch15").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color15.png");';
document.getElementById("exterior-swatch16").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color16.png");';
}
function color5() {
document.getElementById("carerra").src = 'https://www.sanjosecoder.com/porsche-working/images/carerra-s/color5-option1.png';
document.getElementById("exterior-swatch5").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color5-checked.png");';
document.getElementById("exterior-swatch1").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color1.png");';
document.getElementById("exterior-swatch2").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color2.png");';
document.getElementById("exterior-swatch3").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color3.png");';
document.getElementById("exterior-swatch4").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color4.png");';
document.getElementById("exterior-swatch6").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color6.png");';
document.getElementById("exterior-swatch7").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color7.png");';
document.getElementById("exterior-swatch8").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color8.png");';
document.getElementById("exterior-swatch9").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color9.png");';
document.getElementById("exterior-swatch10").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color10.png");';
document.getElementById("exterior-swatch11").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color11.png");';
document.getElementById("exterior-swatch12").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color12.png");';
document.getElementById("exterior-swatch13").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color13.png");';
document.getElementById("exterior-swatch14").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color14.png");';
document.getElementById("exterior-swatch15").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color15.png");';
document.getElementById("exterior-swatch16").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color16.png");';
}
function color6() {
document.getElementById("carerra").src = 'https://www.sanjosecoder.com/porsche-working/images/carerra-s/color6-option1.png';
document.getElementById("exterior-swatch6").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color6-checked.png");';
document.getElementById("exterior-swatch1").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color1.png");';
document.getElementById("exterior-swatch2").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color2.png");';
document.getElementById("exterior-swatch3").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color3.png");';
document.getElementById("exterior-swatch4").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color4.png");';
document.getElementById("exterior-swatch5").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color5.png");';
document.getElementById("exterior-swatch7").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color7.png");';
document.getElementById("exterior-swatch8").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color8.png");';
document.getElementById("exterior-swatch9").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color9.png");';
document.getElementById("exterior-swatch10").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color10.png");';
document.getElementById("exterior-swatch11").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color11.png");';
document.getElementById("exterior-swatch12").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color12.png");';
document.getElementById("exterior-swatch13").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color13.png");';
document.getElementById("exterior-swatch14").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color14.png");';
document.getElementById("exterior-swatch15").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color15.png");';
document.getElementById("exterior-swatch16").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color16.png");';
}
function color7() {
document.getElementById("carerra").src = 'https://www.sanjosecoder.com/porsche-working/images/carerra-s/color7-option1.png';
document.getElementById("exterior-swatch7").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color7-checked.png");';
document.getElementById("exterior-swatch1").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color1.png");';
document.getElementById("exterior-swatch2").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color2.png");';
document.getElementById("exterior-swatch3").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color3.png");';
document.getElementById("exterior-swatch4").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color4.png");';
document.getElementById("exterior-swatch5").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color5.png");';
document.getElementById("exterior-swatch6").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color6.png");';
document.getElementById("exterior-swatch8").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color8.png");';
document.getElementById("exterior-swatch9").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color9.png");';
document.getElementById("exterior-swatch10").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color10.png");';
document.getElementById("exterior-swatch11").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color11.png");';
document.getElementById("exterior-swatch12").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color12.png");';
document.getElementById("exterior-swatch13").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color13.png");';
document.getElementById("exterior-swatch14").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color14.png");';
document.getElementById("exterior-swatch15").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color15.png");';
document.getElementById("exterior-swatch16").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color16.png");';
}
function color8() {
document.getElementById("carerra").src = 'https://www.sanjosecoder.com/porsche-working/images/carerra-s/color8-option1.png';
document.getElementById("exterior-swatch8").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color8-checked.png");';
document.getElementById("exterior-swatch1").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color1.png");';
document.getElementById("exterior-swatch2").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color2.png");';
document.getElementById("exterior-swatch3").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color3.png");';
document.getElementById("exterior-swatch4").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color4.png");';
document.getElementById("exterior-swatch5").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color5.png");';
document.getElementById("exterior-swatch6").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color6.png");';
document.getElementById("exterior-swatch7").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color7.png");';
document.getElementById("exterior-swatch9").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color9.png");';
document.getElementById("exterior-swatch10").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color10.png");';
document.getElementById("exterior-swatch11").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color11.png");';
document.getElementById("exterior-swatch12").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color12.png");';
document.getElementById("exterior-swatch13").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color13.png");';
document.getElementById("exterior-swatch14").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color14.png");';
document.getElementById("exterior-swatch15").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color15.png");';
document.getElementById("exterior-swatch16").style = 'background-image: url("https://www.sanjosecoder.com/porsche-working/images/swatches/exterior/exterior-color16.png");';
}
1条答案
按热度按时间yhqotfr81#
通过对可选择的dom元素进行迭代,可以显著减少代码量。。。
因此,这里是你的电话,以显示该网站的汽车和车轮。。。
<img src="https://www.sanjosecoder.com/porsche-working/images/carerra-s/color15-option3.png" alt="911 Carerra S" id="carerra" />
您有一个轮子的颜色和选项。=>color15-option3
你所需要做的就是在这里插入颜色和轮子的适当索引,然后重新构建你的src链接,以显示显示你的选项的适当图像。我们可以使用html中的dataset属性为input和wheel元素确定颜色索引。
例如,下面的html行是可用颜色的第五行,因此我们将给它一个
data-id
属于5
:为每个select-able元素添加一个datasetattribute,该元素对应于插入src属性以从站点回调正确映像所需的正确字符串。
您所要做的就是创建一个函数来处理两个事件侦听器,一个用于颜色,另一个用于控制盘,每个回调都运行相同的函数来检查事件目标的类。
然后你重建
src
属性以显示要显示的正确图像。document.getElementById('carerra').src = "https://www.sanjosecoder.com/porsche-working/images/carerra-s/color" + selectedColor + "-option" + wheelOption + ".png";
注意:您需要在html中检索颜色和控制盘的默认设置,这可以使用以下方法完成:.split
默认src字符串上的函数。我们使用此方法定义每个默认控制盘和颜色,然后在每次使用条件按钮触发单击事件时插入它们。这是您对上面列出的代码的修改。。。JSFIDLE