Javascript JQuery-不是第一个
我怎么能说Javascript JQuery-不是第一个,javascript,jquery,Javascript,Jquery,我怎么能说 On Click .not.first() div alert('Yeah you clicked a div which is not the first one!'); 我的实际代码: this.$('thumbnails').children().click(function() { $('#video').animate({width: 164, height: 20, top: 475, marginLeft: 262},0)
On Click .not.first() div
alert('Yeah you clicked a div which is not the first one!');
我的实际代码:
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
});
有一个(大于索引)选择器或(@)的首选项:),您的问题按字面翻译为:
$("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!');
});
关于您的最新问题:
$('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;
});
$('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
});
注意使用,如果要立即更改非动画样式,请使用此istead
$("#id").not(':first').click(function(){
alert('Not the first');
});
请参阅jquery文档中的和
$('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
});
将是您问题更新的答案
$('div').not(':first').click(function() {
alert('Yeah you clicked a div which is not the first one!');
});
关于您的最新问题:
$('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;
});
$('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
});
你可以发布一个当前
点击处理程序的示例吗?为什么要在not和第一个选择器的组合上使用它?@Justin-更快,更少输入,更少创建的对象?:)@唐宁街-有什么评论吗?这既正确又简短…所以我很好奇。一般来说,避免将非CSS标准选择器(如:gt
)放在标准表达式中。使用任何非标准功能都意味着必须使用Sizzle JS选择器引擎而不是快速本机querySelectorAll
API来解析整个选择器。通常,最好使用标准选择器和过滤功能相结合。没有gt()
函数,但是$('div')。slice(1)
会做同样的事情。@bobince-虽然我原则上不反对,但您也在创建另一个jQuery对象来做这件事。更重要的是,我发现这一点在这里没有意义,因为:first
也不是有效的CSS选择器,它是特定于jQuery的。为什么要为此再次启动选择器引擎?没有必要,事实上这样做是非常浪费的。不用担心,但正如下面Nick指出的,如果需要即时动画,最好使用.css而不是.animate。