0

我正在使用http://www.dhtmlgoodies.com/index.html?whichScript=quiz-maker但我希望能够为每个问题显示一张图片。

我已经尝试将类似的内容添加到每个部分,但它似乎不起作用。

        (new Image()).src = "http:/track.me/image.gif"; 

        var img = new Image(1,1); // width, height values are optional params 
        img.src = 'http://www.testtrackinglink.com';

这是下面的问题变量。

        var questions = [
                {
                    label : 'Name Arsenals Football Ground?',
                    options : ['Emirates Stadium', 'Old Trafford', 'Stamford Bridge'],
                    answer : ['Emirates Stadium'],
                    forceAnswer : true,


                },
                {
                    label : 'Who was the champion of this years soccer world cup in South Africa ?',
                    options : ['Brazil', 'Netherlands', 'Spain'],
                    answer : ['Spain'],
                    forceAnswer : true  
                },
                {
                    label : 'Name two former Arsenal players ?',
                    options : ['Thierry Henry', 'Tony Adams', 'Michael Owen', 'Ole Gunnar Solskjaer'],
                    answer : [0,1], // refers to the second and third option
                    forceAnswer : true
                }
                ,
                {
                    label : 'United States has how many states',
                    options : ['49','50','51'],
                    answer : ['50'],
                    forceAnswer : true
                },
                {
                    label : 'A crocodile is a member of which family ?',
                    options : ['amphibian','reptile', 'vermin'],
                    answer : ['reptile'],
                    forceAnswer : true
                },
                {
                    label: 'In which year did Atlanta(US) arrange the summer olympics ?',
                    options : ['1992','1996','2000'],
                    answer :['1996'],
                    forceAnswer : true
                }

            ]
4

2 回答 2

1

创建一个新图像并不意味着它也被附加到 DOM 中。您必须手动添加它。

var img = new Image();
img.src = 'http://www.example.com/images/img.jpg';

document.body.appendChild(img);

此外,在运行 javascript 之前,请确保要附加图像的元素存在。

于 2012-08-06T12:14:04.027 回答
0

试试这个,让我知道。

使用 jQuery

$.each(questions, function(i){
   var img = new Image();
   img.src='http://www.example.com/images/img.jpg';
   document.body.appendChild(img);
});

没有jQuery

for(var i=0;i<questions.length;i++){
   var img = new Image();
   img.src='http://www.example.com/images/img.jpg';
   document.body.appendChild(img);
});
于 2012-08-06T12:16:25.357 回答