Javascript JQuery - 不是第一
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/4304587/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
JQuery - not first
提问by Tomkay
How can I say..
我怎么能说..
On Click .not.first() div
alert('Yeah you clicked a div which is not the first one!');
My actual code:
我的实际代码:
this.$('thumbnails').children().click(function() {
$('#video').animate({width: 164, height: 20, top: 475, marginLeft: 262},0)
$('.flv').animate({left: 2222, opacity: '0'},0).css('display', 'none')
$('.close').animate({opacity: '0'},0)
clicked = 0
});
回答by Nick Craver
There's a :gt()
(greater-than-index) selector or .slice(1)
(@bobince's preference :), your question translated literally would be:
有一个:gt()
(大于索引)选择器或.slice(1)
(@ bobince的偏好:),您的问题按字面翻译为:
$("div:gt(0)").click(function() {
alert('Yeah you clicked a div which is not the first one!');
});
//or...
$("div").slice(1).click(function() {
alert('Yeah you clicked a div which is not the first one!');
});
For your updated question:
对于您更新的问题:
$('thumbnails').children(":gt(0)").click(function() {
$('#video').css({width: 164, height: 20, top: 475, marginLeft: 262});
$('.flv').css({left: 2222, opacity: '0'}).hide();
$('.close').css({opacity: '0'});
clicked = 0;
});
//or...
$('thumbnails').children().slice(1).click(function() {
$('#video').css({width: 164, height: 20, top: 475, marginLeft: 262});
$('.flv').css({left: 2222, opacity: '0'}).hide();
$('.close').css({opacity: '0'});
clicked = 0;
});
Note the use of .css()
, if you want to make instant non-animated style changes, use this istead.
请注意 的使用.css()
,如果您想进行即时的非动画样式更改,请改用此。
回答by dotty
$(div).not(":first").click(function(){
alert("Yeah you clicked a div which is not the first one!);
});
see :firstand .notfrom the jquery docs.
$('thumbnails').children().not(":first").click(function() {
$('#video').animate({width: 164, height: 20, top: 475, marginLeft: 262},0)
$('.flv').animate({left: 2222, opacity: '0'},0).css('display', 'none')
$('.close').animate({opacity: '0'},0)
clicked = 0
});
Would be the answer for the update to your question.
将是您问题更新的答案。
回答by Capt Otis
$("#id").not(':first').click(function(){
alert('Not the first');
});
回答by cspolton
$('div').not(':first').click(function() {
alert('Yeah you clicked a div which is not the first one!');
});
For your updated question:
对于您更新的问题:
$('thumbnails').children().not(':first').click(function() {
$('#video').animate({width: 164, height: 20, top: 475, marginLeft: 262},0)
$('.flv').animate({left: 2222, opacity: '0'},0).css('display', 'none')
$('.close').animate({opacity: '0'},0)
clicked = 0
});