English 中文(简体)
地图级名称:使用j Query分离阵列
原标题:Map classnames to separate arrays using jQuery

请允许我说,我们有以下的:

 <ul id="portfolio-list" class="clearfix span-24">

  <li class="2012#foo bar car#cat_1">item 1 <br /></li>
  <li class="2011#car foo fly#cat1">item2 <br /></li>
  <li class="2009#car fly swat_car#cat_2">item3<br /></li>
  <li class="2012#bar show car#cat_3">item 4<br /></li>

</ul>

and I want to create a map the classes each item to do the following:

  1. I m trying to split the code into three parts
  2. output each piece and
  3. add them to their own array of values.

采用以下代码,它只能从最后一份清单中收回价值。

我怎样把它放在名单上的项目之上,并增加每个项目的价值。

守则如下:

jQuery(document).ready(function($) {
    var splitList = $("#portfolio-list li").map(function() {
        inStringy = $(this).attr("class").split( # );
        list = $(this).attr( class );
        list = list.split("#").join(" ");
        $(this).removeClass();
        var that = $(this);
        $(that).addClass(list);
        return inStringy;
    });

    cla = [];
    yr = inStringy[0]; 
    classListin[classListin.length] = cla + "";
    categoryListin[categoryListin.length] = cat + " ";
    cla = inStringy[1];
    cla = cla.split(" ");
    cat = inStringy[2];
    yearListin = [];
    classListin = [];
    categoryListin = [];
    yearListin[yearListin.length] = yr + "";
    classListin[classListin.length] = cla + "";
    categoryListin[categoryListin.length] = cat + " ";
});

任何帮助都值得赞赏!

最佳回答

Globals all over the place! See comments for explanations.

// answer moved to fiddle: http://jsfiddle.net/VyFc8/

问题回答

暂无回答




相关问题
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.

热门标签