【问题标题】:Link for list item doesn't work列表项的链接不起作用
【发布时间】:2011-05-10 18:09:07
【问题描述】:

我想在这个列表项上创建一个链接。为什么这个方法不起作用?

#jQuery(function(){     
var theList = jQuery('#someList'); 
var content = jQuery('<a href="Settings"><li id="content'+i+'"></li><a/>' 
theList.append(content);        

【问题讨论】:

  • 您的&lt;a&gt;&lt;li&gt; 标签是从头到尾的! =)

标签: jquery jquery-mobile


【解决方案1】:

你需要刷新列表:

theList.append(content).listview('refresh');

更新:你的代码

jQuery(function(){ 
    var theList = jQuery('#someList'); 

    for(i=0; i < mytool_array.length; i++) { 
        content = '<li id="content'+i+'"><a href="dgdfg"></a></li>'; 
        theList.append(content); 
    } 
    theList.listview('refresh'); 
});

【讨论】:

  • 我没有完成这项工作,因为在循环中刷新不能正常工作。
  • 那么就在循环之后执行它:theList.listview('refresh');
  • 我在循环后进行了刷新,但我得到了视图但链接不起作用。
  • 您是否按照其他帖子的建议将锚标记更改为列表项标记内?
  • 是的,它现在看起来像这样: jQuery(function(){ var theList = jQuery('#someList'); for(i=0; i'; theList.append(content); } theList.listview('refresh'); })
  • 【解决方案2】:

    您的代码中似乎缺少括号,试试这个?

    var theList = $('#someList'),
        i = 0, // i isn't defined in the code you displayed, is it in a loop by chance?
        content = '<li id="content' + i + '"><a href="Settings">Put Something Here</a></li>';
    theList.append(content); 
    

    【讨论】:

      猜你喜欢
      相关资源
      最近更新 更多
      热门标签