2012-05-02 76 views
0

我有一个Sharepoint站点动态地从列表中获取名称和描述。使用jquery隐藏和显示动态创建的段落

var name = $(this).attr('ows_Title'); //This is the internal storage name in SP 
var comments = $(this).attr('ows_MetaInfo').match(/^_Comments:SW\|(.*)$/m); 

我再服用这些VAR和他们送入空的div我的网页上(在div被称为“文档列表”)

 var item = "<a class='docLinks' href='http:path/to/the/doc/" + name + "'>" 
+ title + "</a><br><p><span class='description' id='para_" + i + "'>" 
    + comments + "</span></p><br>"; 
     $('#docList').append(item); 

我想使它这样的“评论”即项目的描述,出现在悬停在项目名称下方。

我试图在这个主题上各种迭代:

 $('#docList a').hover(function(){ 
      $(this).child().css({'display':'block'})}, 
      function(){ 
       $(this).child().css({'display':'none'}); 
     }); 

我知道,我可以访问悬停事件,因为我在一些简单的警报编码,他们都很好。

最初,我试着给每个'评论'它自己的(正如你所看到的),但得到绊倒获取索引值。然后我决定尝试使用

 $(this).children('.description').css({'display':'block'}); 

但是没有运气。我关门了吗?我在哪里搞砸语法?

回答

1
$(this).nextUntil('p').next().find('.description').hide() 

$(this).nextUntil('p').next().find('.description').show() 

,你不需要id

+0

感谢您的快速反应,幻象.....我应该提到的描述已经隐藏的,所以我正是如此翻转你的代码: $('#docList a')。hover(function(){(this).nextUntil('p')。next()。find('。description')。show();} ,function ){ $(this).nextUntil('p')。next()。find('。description')。hide(); }); 它不工作。我在哪里拧这个? – mrwienerdog

+0

检查http://jsfiddle.net/jV5KM/,everyting很好(我添加了'last()',但它不是必需的) – phantasm

+0

我真的很感激你接受这样的时间......出于某种原因,我可以不要让该死的东西在我的CEWP中工作,但......不知道f是怎么回事...... – mrwienerdog