【发布时间】:2017-10-21 15:08:30
【问题描述】:
我是学习 jQuery 的学生,我的目标是使用 optionArray 索引中的 4 个对象将数组中的每个对象附加到 4 个不同的按钮。目前它只附加 optionArray 的索引 i 的单个按钮,如下所示:Radio Head、Gorillaz、Coldplay、Arctic Monkeys。
我希望它在 optionsArray 的索引 i 中单独附加每个对象作为 4 个不同的按钮。例如:
- 收音机头
- 大猩猩
- 酷玩游戏
- 北极猴
我不确定如何执行此操作...感谢您提供的任何高级帮助。
JS:
window.onload = function() {
$('#start').html('<div class="text-center"><button type="button" class="btn btn-default">Start</button></div>');
};
var questionArray = ["This bands second album went platinum 5 times in the UK and double Platinum in the US."];
var optionArray = [["Radio Head", "Gorillaz", "Coldplay", "Arctic Monkeys"], []];
var answerArray= ["Gorillaz"];
var imageArray= ["http://cdn3.pitchfork.com/artists/1767/m.65d9c64d.jpg", "http://crowningmusic.com/storage/rA7GUFFoBCtT8Jg4L1tv.png", "", "", ""];
var count = 0;
$("#start").on('click', function() {
$(this).css("display","none");
for (var i = 0; i < questionArray.length; i++) {
$("#question").html(questionArray[i]);
for (var j = 0; j < 4; j++) {
$("#options").append("<button>" + optionArray[i] + "</button>");
}
}
// $("#holder").html("<img src=" + questionArray[count] + ">");
});
【问题讨论】:
-
您的目标很难理解“我希望它将索引 i 中的每个索引附加为 4 个不同的按钮。”
-
这是您要找的吗? jsfiddle.net/36zck6dk
标签: javascript jquery arrays append