English 中文(简体)
2. 在飞行中建立阵列
原标题:Creating nested arrays on the fly

我正试图这样做,是穿透这一超文本,并获取一阵nes的这种超文本价值,即希望 gr。

It might look complex at first but is a simple question...

html

<div class="configureData">
               <div title="Large">
                  <a href="yellow" title="true" rel="$55.00" name="sku22828"></a>
                  <a href="green" title="true" rel="$55.00" name="sku224438"></a>
                  <a href="Blue" title="true" rel="$55.00" name="sku22222"></a>
                </div>
              <div title="Medium">
                  <a href="yellow" title="true" rel="$55.00" name="sku22828"></a>
                  <a href="green" title="true" rel="$55.00" name="sku224438"></a>
                  <a href="Blue" title="true" rel="$55.00" name="sku22222"></a>
                </div>
             <div title="Small">
                  <a href="yellow" title="true" rel="$55.00" name="sku22828"></a>
                  <a href="green" title="true" rel="$55.00" name="sku224438"></a>
                  <a href="Blue" title="true" rel="$55.00" name="sku22222"></a>
             </div>
   </div>

javascript

  //This script is just part of a Object containing methods.
parseData:function(dH){
        dH.find(".configureData div").each(function(indA, eleA){
                   colorNSize.tempSizeArray[indA] = [eleA.title,[],[],[]]
                     $(eleZ).find("a").each(function(indB, eleB){
                              colorNSize.tempSizeArray[indA][indB] = eleB.title
              })
            })
        },

我希望最后几个阵列也这样做。

 [
   ["large", 
      ["yellow", "green", "blue"],
      ["true", "true", "true"],
      ["$55", "$55","$55"]
   ],
   ["Medium", 
      ["yellow", "green", "blue"],
      ["true", "true", "true"],
      ["$55", "$55","$55"]
   ]
 ]
// and so on....
最佳回答

鉴于您的超文本和这一格文,

var result = [];
$( .configureData div ).each(function () {
    var $a = $( a , this);
    result.push([this.title,
            $.map([ href ,  title ,  rel ], function (a) {
                return [$.map($a, function (v) {
                    return $(v).attr(a)
                })];
            })

    ]);
});

您获得<代码>result,确定了您要求的方式。

如果有火药,请参看console.dir(result)

www.un.org/Depts/DGACM/index_spanish.htm Edit:我更新了文字,将武断的属性引入单独的次导线。

问题回答

这样做就好了。 (Your Code wasn tm off.)

parseData:function(dH){
  var results = [];
  dH.find(".configureData div").each(function(indA, eleA){
    var div = $(this);
    var result = [div.attr( title ),[],[],[]];
    results[results.length] = result;
    div.find("a").each(function(indB, eleB){ 
      var link = $(this);
      result[1][result[1].length] = link.attr( href );
      result[2][result[2].length] = link.attr( title );
      result[3][result[3].length] = link.attr( rel );
    });
  });
} 




相关问题
selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

How to fire event handlers on the link using javascript

I would like to click a link in my page using javascript. I would like to Fire event handlers on the link without navigating. How can this be done? This has to work both in firefox and Internet ...

How to Add script codes before the </body> tag ASP.NET

Heres the problem, In Masterpage, the google analytics code were pasted before the end of body tag. In ASPX page, I need to generate a script (google addItem tracker) using codebehind ClientScript ...

Clipboard access using Javascript - sans Flash?

Is there a reliable way to access the client machine s clipboard using Javascript? I continue to run into permissions issues when attempting to do this. How does Google Docs do this? Do they use ...

javascript debugging question

I have a large javascript which I didn t write but I need to use it and I m slowely going trough it trying to figure out what does it do and how, I m using alert to print out what it does but now I ...

Parsing date like twitter

I ve made a little forum and I want parse the date on newest posts like twitter, you know "posted 40 minutes ago ","posted 1 hour ago"... What s the best way ? Thanx.

热门标签