2013-05-14 37 views
0

jQuery的運行功能,我想運行基礎上,EQ()選擇一個功能:上選擇

$('div.entry-content div.one_fifth').eq(0, function(){ 
    $(this).css({background: 'url(../wp-content/themes/genesis/images/plant_hire.jpg) no-repeat center'}); 
    $(this).on('hover',function(){ 
    alert('Test'); 
    }); 
}); 

什麼是錯的,因爲裏面的功能我的語法不工作

感謝

+1

'.eq()'沒有回調。 – j08691 2013-05-14 18:20:06

+1

.eq()方法不會也不應該接受第二個參數。 – 2013-05-14 18:20:20

+0

是啊...但你知道我想做什麼...這是最好的,因爲我可以解釋它... – DextrousDave 2013-05-14 18:21:33

回答

3

這將選擇您的選擇器的零索引,更改css,然後附加懸停的事件處理程序。

$('div.entry-content div.one_fifth') 
    .eq(0) 
    .css({background: 'url(../wp-content/themes/genesis/images/plant_hire.jpg) no-repeat center'}) 
    .on('hover',function(){ 
     alert('Test'); 
    }); 

編輯,我剪切和粘貼的OP原來有什麼,我只是認爲沒有語法錯誤。

+2

你有一個額外的'});',否則看起來不錯。 – 2013-05-14 18:21:57

+0

@KevinB謝謝,編輯。 – 2013-05-14 18:22:36

+0

刪除;之後css – PSL 2013-05-14 18:22:40