English 中文(简体)
许可证数额和增加联系
原标题:Limit amount of LI and add more link
  • 时间:2012-05-13 23:14:38
  •  标签:
  • jquery
  • limit

我正在动态地编制多个清单,首先需要将其限制在5个,然后有“More”链接,应当从最接近的同父系关系中提取。

This is what I have so far....

页: 1

<h2><a class="parentcat" title="" href="#">Heading</a></h2>
<ul class="subcat">
      <li><a href="#">Link 1</a></li>
      <li><a href="#">Link 2</a></li>
      <li><a href="#">Link 3</a></li>
      <li><a href="#">Link 4</a></li>
      <li><a href="#">Link 5</a></li>
</ul>


$(function () {
    var link = ($(this).find( a.parentcat ).attr( href ));

    $("ul.subcat").each(function () {
        $("li:gt(5)", this).hide(); /* :gt() is zero-indexed */
        $("li:nth-child(6)", this).after("<li class= more ><a href= # >More...</a></li>"); /* :nth-child() is one-indexed */
    });
});

这限制了人们所展示的电离辐射量,但这种变数只是发现在许多表面的tag子中,它应当找到最接近的UL。 很可能是一个非常令人sil笑皆是的问题,我把变数带入我失败的所有尝试。

问题回答

您需要检索<代码>each的路程。 否则,.attr()将始终使用j Query标语中的第一点。

$("ul.subcat").each(function () {
    var link = $(this).prev( h2 ).find( a.parentcat ).attr( href );
    $("li:gt(5)", this).hide(); /* :gt() is zero-indexed */
    $("li:nth-child(6)", this).after("<li class= more ><a href= # >More...</a></li>"); /* :nth-child() is one-indexed */
});

页: 1 a. 阵列中所有<代码>href:

var links = [];
$( a.parentcat ).each(function(i, v){
   links[i] = $(this).attr( href );
})




相关问题
getGridParam is not a function

The HTML: <a href="javascript:void(0)" id="m1">Get Selected id s</a> The Function: jQuery("#m1").click( function() { var s; s = jQuery("#list4").getGridParam( selarrrow )...

selected text in iframe

How to get a selected text inside a iframe. I my page i m having a iframe which is editable true. So how can i get the selected text in that iframe.

jQuery cycle page with links

I am using the cycle plugin with pager functionality like this : $j( #homebox ) .cycle({ fx: fade , speed: fast , timeout: 9000, pager: #home-thumbs , ...

jquery ui dialog opens only once

I have a button that opens a dialog when clicked. The dialog displays a div that was hidden After I close the dialog by clicking the X icon, the dialog can t be opened again.

jConfirm with this existing code

I need help to use jConfirm with this existing code (php & Jquery & jAlert). function logout() { if (confirm("Do you really want to logout?")) window.location.href = "logout.php"; } ...

Wrap text after particular symbol with jQuery

What I m trying to do, is wrap text into div inside ll tag. It wouldn t be a problem, but I need to wrap text that appears particularly after "-" (minus) including "minus" itself. This is my html: &...

热门标签