使用jquerymobile追加到列表
我想循环页面并附加/创建链接到主要内容。如何做到这一点?这就是我目前所拥有的 我用的是jquery手机 谢谢使用jquerymobile追加到列表,jquery,jquery-mobile,Jquery,Jquery Mobile,我想循环页面并附加/创建链接到主要内容。如何做到这一点?这就是我目前所拥有的 我用的是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', $('
$.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="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>
etc根据问题编辑更新答案
$。每个(站点数据[“页面]),功能(i,v){
//查找contentdiv并在其中插入链接
$.mobile.activePage.find('[data role=content]')。append('');
});
旧答案:
$.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);
});
$。每个(站点数据[“页面]),功能(i,v){
//附加href链接
$.mobile.activePage.find('[data role=content]a').attr('href',siteData.id)
//附加链接的文本
$.mobile.activePage.find('[data role=content]a').html(文本);
//更改标题文本
$.mobile.activePage.find('[data role=header]h3').html(siteData.name);
});
根据问题编辑更新答案
$。每个(站点数据[“页面]),功能(i,v){
//查找contentdiv并在其中插入链接
$.mobile.activePage.find('[data role=content]')。append('');
});
旧答案:
$.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);
});
$。每个(站点数据[“页面]),功能(i,v){
//附加href链接
$.mobile.activePage.find('[data role=content]a').attr('href',siteData.id)
//附加链接的文本
$.mobile.activePage.find('[data role=content]a').html(文本);
//更改标题文本
$.mobile.activePage.find('[data role=header]h3').html(siteData.name);
});
这很酷,谢谢,但您的代码似乎正在替换,而不是追加。要追加还是替换@马库克,我真的想替换,不,对不起。但是我没有看到我应该看到的链接列表。mobile.activePage.find('[data role=content]a').attr('href',“a”);所以我认为它每次都在替换它每次都在替换,因为您正在使用$.each()
循环。在您的情况下,要一次性注入数据,您不需要使用$。我需要使用每个:)来列出所有数据。我只想显示所有页面的列表,也就是说,这是我正在尝试创建的导航。这很酷,谢谢,但您的代码似乎正在替换而不是附加。您想附加还是替换@马库克,我真的想替换,不,对不起。但是我没有看到我应该看到的链接列表。mobile.activePage.find('[data role=content]a').attr('href',“a”);所以我认为它每次都在替换它每次都在替换,因为您正在使用$.each()
循环。在您的情况下,要一次性注入数据,您不需要使用$。我需要使用每个:)来列出所有数据。我只想显示所有页面的列表,也就是说,这是我试图创建的导航。
$.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);
});