English 中文(简体)
页: 1 with with
原标题:jQuery menu with XML

为了诚实,我用 t子仍然使用XML。

我有一点XML(下文):

<folder title="Home">
  <item title="Welcome" />
  <folder title="My Photos">
    <folder title="Holidy">
      <item title="Photo 1" />
      <item title="Photo 2" />
      <item title="Photo 3" />
      <item title="Photo 4" />
      <item title="Photo 5" />
    </folder>
    <folder title="Christmas">
      <item title="Photo 1" />
      <item title="Photo 2" />
      <item title="Photo 3" />
      <item title="Photo 4" />
      <item title="Photo 5" />
      <item title="Photo 6" />
      <item title="Photo 7" />
      <item title="Photo 8" />
    </folder>
    <folder title="Zoo">
      <item title="Photo 1" />
      <item title="Photo 2" />
      <item title="Photo 3" />
      <item title="Photo 4" />
    </folder>
  </folder>
  <folder title="My Videos">
    <item title="Movie 1" />
    <item title="Movie 2" />
    <item title="Movie 3" />
    <item title="Movie 4" />
    <item title="Movie 5" />
    <item title="Movie 6" />
    <item title="Movie 7" />
    <item title="Movie 8" />
  </folder>
  <folder title="My Audio">
    <folder title="Artist 1">
      <folder title="Album 1">
        <item title="Track 1" />
        <item title="Track 2" />
        <item title="Track 3" />
        <item title="Track 4" />
        <item title="Track 5" />
        <item title="Track 6" />
        <item title="Track 7" />
      </folder>
      <folder title="Album 2">
        <item title="Track 1" />
        <item title="Track 2" />
        <item title="Track 3" />
        <item title="Track 4" />
        <item title="Track 5" />
        <item title="Track 6" />
        <item title="Track 7" />
        <item title="Track 8" />
      </folder>
    </folder>
    <folder title="Artist 2">
      <folder title="Album 1">
        <item title="Track 1" />
        <item title="Track 2" />
        <item title="Track 3" />
        <item title="Track 4" />
        <item title="Track 5" />
        <item title="Track 6" />
        <item title="Track 7" />
      </folder>
    </folder>
    <folder title="Podcasts">
      <item title="Track 1" />
      <item title="Track 2" />
      <item title="Track 3" />
      <item title="Track 4" />
      <item title="Track 5" />
      <item title="Track 6" />
      <item title="Track 7" />
      <item title="Track 8" />
    </folder>
  </folder>
</folder>

并且我希望按此顺序排列(以下简称)

<div class="entry">
   <p><span class="links">Sub-directory</span></p>
   <p><span class="files">File One</span></p>
   <p><span class="files">File Two</span></p>
   <p><span class="files">File Three</span></p>
   <p><spanclass="files">FileFour</span></p>
   <p><spanclass="files">FileFive</span></p>
   <p><span class="files">File Six</span></p>
</div>

and I want to navigate inside... I have understand how to load the XML but I didn t understand how to put inside the span TAG the title text. And when naveigate into "My Photos"... how to see the child contents...

事先得到帮助。

EDIT:

The jQuery (below):

$.ajax({
        type: "GET",
        url: "content.xml",
        dataType: "xml",
        success: function (xml) {
            $(xml).find( Home ).children().each(function () {

                var title_text = $(this).attr( title );
                var spanFiles = $( span.files );

                spanFiles
                    .html(title_text)
                    .appendTo( div.entry );

            });
        }
    });

但不从事工作......

最佳回答

Just use xml as datatype with the load function, as I think was the road you walked. Then you must loop your top folder. But first, your xml should be like this:

<folders>
    <folder>
        <subfolder>
            <item></item>
        </subfolder>
    </folder>
</folders>

你们为什么使用所有权? 应使用:文本

接着,每一方都利用你手套:

$(xml).find( folder ).each(function() {
});

And in there you can check if there s a subfolder:

if($(this).find( subfolder ).length > 0) { //loop the items from the subfolder }

仅从一个项目获得案文:

$(this).find( item ).text();

首先,如果你再次失败,你就会被罚款。 并且记住说什么不是工作,而不是工作。

EDIT: And in your code you re replacing the contents of that span over and over again. EDIT2: This is how you should append your items:

var text = $(this).find( item ).text(),
    $span = $(document.createElement( span )).addClass( files );

$span.html(text).appendTo( div.entry );
问题回答

暂无回答




相关问题
CSS working only in Firefox

I am trying to create a search text-field like on the Apple website. The HTML looks like this: <div class="frm-search"> <div> <input class="btn" type="image" src="http://www....

image changed but appears the same in browser

I m writing a php script to crop an image. The script overwrites the old image with the new one, but when I reload the page (which is supposed to pickup the new image) I still see the old one. ...

Firefox background image horizontal centering oddity

I am building some basic HTML code for a CMS. One of the page-related options in the CMS is "background image" and "stretch page width / height to background image width / height." so that with large ...

Separator line in ASP.NET

I d like to add a simple separator line in an aspx web form. Does anyone know how? It sounds easy enough, but still I can t manage to find how to do it.. 10x!

热门标签