English 中文(简体)
使用 LT 选择器的 Jquery 最后一个元素
原标题:Jquery last element with LT Selector
  • 时间:2012-05-26 21:34:25
  •  标签:
  • jquery

我试图摧毁除最后一个元素之外的所有元素 除了这行的Jquery代码:

$(".message_list .message_body:lt(:last-child)").hide();

这条线没有崩溃,我试过

 :last child 
:last-child
last()
:last
 :last 

没有什么能给我最后一个元素。 我如何选择比最后一个元素更少的元素? lt () 中写了什么?

最佳回答

尝试此 :

$(".message_list .message_body:not(:last-child)").hide();

或取决于您的 HTML 结构, 您可能需要 < code>: last 。

$(".message_list .message_body:not(:last)").hide();
问题回答

< a href=" "http://api.jquery.com/lt-selector/" rel="nofollow"\\\ code >:lt 将零基索引作为参数,而不是选择符。 如果您 必须 使用 :lt :

var items = $( .message_list .message_body );
var lastItem = $( .message_list .message_body:last );
var index = items.index(lastItem);

$(".message_list .message_body:lt(" + index + ")").hide();

否则,请使用@rorys 回答。

$(".message_list .message_body:not(:last)").hide();    

工作样本:"http://jsfiddle.net/WnCeH/2/" rel="nofollow">http://jsfiddle.net/WnCeH/2/

这里的样本可以帮助您从概念上找到解决问题的方法: http://jsfiddle.net/T5ZVE/

它使用: >not





相关问题
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: &...

热门标签