2010-11-19 43 views
1

我對id屬性有不同的值,我需要發送到花式框。將ID的值發送到花式框

$('a.Links').click(function() {       
    var clickID = $(this).attr('id') ; 
    alert(clickIDID); 
}); 

$("#"+clickID).fancybox({ 
    'width' : '75%', 
    'height' : '75%', 
    'autoScale' : false, 
    'transitionIn' : 'none', 
    'transitionOut' : 'none', 
    'type' : 'iframe', 
    'titlePosition' : 'outside', 
    'content' : 'testl' 
}); 

如何將clickID的值發送到.fancy框。我試圖在點擊功能中添加.fancybox,但這不起作用。具體參考前面的問題
the index value of attribute

回答

3

假設所有的ID開始與詞 'popup_',(popup_1,popup_2等),那麼你可以使用Attribute Starts With選擇這樣的:

// initialize fancybox for all elements with ID starting with 'popup_' 
$("[id^=popup_]").fancybox({ 
    'width' : '75%', 
    'height' : '75%', 
    'autoScale' : false, 
    'transitionIn' : 'none', 
    'transitionOut' : 'none', 
    'type' : 'iframe', 
    'titlePosition' : 'outside', 
    'content' : 'testl' 
}); 

然而,使用class屬性來集體解決這些問題會更直截了當,如下所示:

<a class="popup">Foo</a> 
<img class="popup" src="foo.jpg"/> 

$(".popup").fancybox({ 
    ... 
+0

問題是我有idexed值。請查看我以前的排隊詳情 – user512438 2010-11-19 01:44:12

+0

http://stackoverflow.com/questions/4221269/the-index-value-of-attribute – user512438 2010-11-19 01:44:49

+1

'$(「a [id^= read]」)。fancybox({... 「應該這樣做,除非我失去了一些東西,幾乎和我描述的一樣。 – karim79 2010-11-19 01:46:55