我和一个班有联系
<a href="/blah/1234", class="modal">Blah</a>
但我需要告诉lightbox,如果它有效的话,就要使用href+.js扩展。这样,如果用户没有js或者由于任何原因中断,它就会将它们发送到回退页面并正常工作。
$('.modal').lightbox({ 'width' : 465, 'height' : 375, 'autoresize' : false, 'modal' : true });
这样做效果很差,但每次添加.js时,单击一次就会中断。
$('.modal').bind('click', function() { $('.modal').attr("href", $('.modal').attr("href") + '.js'); $('.modal').lightbox({ 'width' : 465, 'height' : 375, 'autoresize' : false, 'modal' : true }); });
您可以使用函数 .attr() 检查它是否 .js ,就像这样:
.attr()
.js
$('.modal').attr("href", function(i, href) { return href + (href.slice(-3) == '.js' ? '' : '.js'); });
或者,对所有的链接 ready
ready
$('.modal').attr('href', function(i, href) { return href + '.js'; }).lightbox({ 'width' : 465, 'height' : 375, 'autoresize' : false, 'modal' : true });