0

http://www.dhtmlgoodies.com/index.html?whichScript=quiz-makerを使用していますが、質問ごとに画像を表示できるようにしたいと考えています。

iveはすでにこのようなものを各セクションに追加しようとしましたが、うまくいかないようです。

        (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 に答える