1

ページをループして、メイン コンテンツへのリンクを追加/作成したい。これはどのように行うことができますか?これは私がこれまでに持っているものです。

私はjqueryモバイルを使用しています。

ありがとう。

 $.mobile.activePage.removeClass('ui-body-a ui-body-b ui-body-c ui-body-d ui-body-e')
         .addClass('ui-body-' + $('div[data-theme]','#index').data('theme'))
         .attr('data-theme', $('div[data-theme]','#index').data('theme'));

 //pages
 $.each(siteData["pages"], function(i,v) {
      //HERE I WANT TO APPEND ID TO href TITLE AND VALUE TO CONTENT
 });

HTML

<div data-role="page" id="index">
    <div data-theme="a" data-role="header">
        <h3>Loading...</h3>

    </div>

    <div data-role="content">

        <a href="#two" data-role="button">Show page "two"</a>


    </div>

    <div data-role="footer">
        <h4></h4>
    </div><!-- /footer -->
</div>

だから私が見たいのはこのようなものです....

<div data-role="content">

    <a href="#1" data-role="button">Show page "1"</a>
    <a href="#2" data-role="button">Show page "2"</a>
   <a href="#3" data-role="button">Show page "3"</a>


</div>

4

1 に答える 1

1

回答の更新-質問の編集に基づいています。

$.each(siteData["pages"], function(i,v) {

 // find content div and insert links inside it
 $.mobile.activePage.find('[data-role=content]').append('<a href=' + id + ' data-role="button">' + text + '</a>');

});

古い答え:

 $.each(siteData["pages"], function(i,v) {

 // append href link
 $.mobile.activePage.find('[data-role=content] a').attr('href', siteData.id)

 // append text of <a> link
 $.mobile.activePage.find('[data-role=content] a').html(text);

 // change the header text
 $.mobile.activePage.find('[data-role=header] h3').html(siteData.name);

});
于 2013-03-30T22:23:42.643 に答える