为每个div分隔每个描述

时间:2012-04-11 16:37:57

标签: jquery

此代码工作正常,但我遇到了问题。当我点击每个元素时,从第一个元素开始,我的描述将出现在订单中。但是当我点击第五个描述(例如)时,它只是出现的第一个描述。谢谢你的回复。

这是我的新代码:

$(function() {

var works = new Array();

works[0] = new Array('facebook.png','Text description 0.','http://www.facebook.com/');
works[1] = new Array('adobe.png','Text description 1.','http://www.adobe.com/');
works[2] = new Array('microsoft.png','Text description 2.','http://www.microsoft.com/');
works[3] = new Array('sony.png','Text description 3.','http://www.sony.com/');
works[4] = new Array('dell.png','Text description 4.','http://www.dell.com/');
works[5] = new Array('ebay.png','Text description 5.','http://www.ebay.com/');
works[6] = new Array('digg.png','Text description 6.','http://www.digg.com/');
works[7] = new Array('google.png','Text description 7.','http://www.google.com/');

//Random works
var shuffle = false;

works.sort(function(){

  if (shuffle == true) {
    return 0.7 - Math.random();
  } else {
      return false;
    }   

});
//End random works

for ( var i = 0; i < works.length; i++ ){

// Create the divs with those ID and CLASS
var work = document.createElement('div');
    work.id = 'workId' + i;
    work.className = 'work';

var workFlip = document.createElement('div');
    workFlip.id = 'workFlipId' + i;
    workFlip.className = 'workFlip';

var workData = document.createElement('div');
    workData.id = 'workDataId' + i;
    workData.className = 'workData';    

var workDescription = document.createElement('div');
    workDescription.id = 'workDescriptionId' + i;
    workDescription.className = 'workDescription';

var workURL = document.createElement('div');
    workURL.id = 'workURLId' + i;
    workURL.className = 'workURL';

    // Insert the content in the respective div
    document.getElementById("workListId").appendChild(work);
    document.getElementById("workId" + i).appendChild(workFlip);
    document.getElementById("workId" + i).appendChild(workData);
    document.getElementById("workDataId" + i).appendChild(workDescription);
    document.getElementById("workDataId" + i).appendChild(workURL);

    // Insert the HTML content
    workFlip.innerHTML ='<img src="img/works/' + works[i][0] + '" >';
    workDescription.innerHTML = works[i][1];
    workURL.innerHTML = '<a href="' + works[i][2] + '" >Read more...</a>';

}//End for
}); // End Function

0 个答案:

没有答案