2010-11-19 44 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