我对盖勒菲有一个问题,它是一种流行的jQuery插件,用于在它们附近显示带有jQuery的图像。
在这个HTML中,我有一个图像,用作按钮:<img class="my_button" src="img/button.gif" />
在<head>和</head>标记之间,我有以下jQuery代码:
<script type="text/javascript">
$(document).ready(function () {
$(".my_button").click(function(){
$.get("page.php",function(data)
{
$('#mydiv').html(data);
});
});
});
</script>问题是jQuery代码在 Galleriffic之前加载,因此在加载$(".my_button").click(){}事件时没有按钮。
有办法在jquery代码之前强制Galleriffic加载吗?
以下是一些需要尽可能明确的代码:
<script type="text/javascript">
$(document).ready(function () {
$(".my_button").click(function(){
$.get("pagea.php",function(data)
{
$('#mydiv').html(data);
});
});
});
</script>
///some html
<script type="text/javascript" src="Galleria Borse/js/jquery.history.js"></script>
// Galleriffic libraries calls
<!-- We only want the thunbnails to display when javascript is disabled -->
<script type="text/javascript">
document.write('<style>.noscript { display: none; }</style>');
</script>
<div class="navigation-container">
<div id="thumbs" class="navigation">
<a class="pageLink prev" style="visibility: hidden;" href="#" title="Previous Page"></a>
<ul class="thumbs noscript">
//and other galleriffic containers and divs
<img class="my_button" src="img/button.gif" /> //this is the button
<script type="text/javascript">
jQuery(document).ready(function($) { //some Galleriffic code (Jquery code) }我试着把代码$(".my_button").click(function(){});放在任何地方:在身体内部,在页面的底部,甚至放在Galleriffic库中。
发布于 2012-02-08 12:51:44
你试过这个吗?
jQuery(document).ready(function($) {
//some Galleriffic code (Jquery code)
// Initialize Minimal Galleriffic Gallery
$('#thumbs').galleriffic({
imageContainerSel: '#slideshow',
controlsContainerSel: '#controls'
});
$(".my_button").click(function(){
$.get("pagea.php",function(data){
$('#mydiv').html(data);
});
});
});发布于 2013-08-15 22:57:37
有点晚了,但无论如何:)。有一个解决方案可以这样做,您甚至可以将代码放在
$(document).ready();
问题是,正如您所说的,当您想要绑定单击事件时,没有什么可以绑定到它。所以,为什么不把它绑定到不同的东西上。有一个可能性
.on()
自jQuery 1.7 (约)开始。在这个版本中,.on也使用了.bind、.delegate和.live的功能。我们对.delegate风格很感兴趣:)。
所以而不是
$(".my_button").click(function(){})使用
$('#foo').on('click','.my_button', function(){})这样做是为了将.on event绑定到#foo,这可以是任何东西,从一开始就在页面上(比如$(document))。并说“当您看到一些.my_button单击时触发单击事件,这意味着,当.my_button最终到达时,它将工作:)。
顺便说一句,这是解决Galleriffic "harcore“定制的另一个问题的一种方法:)。这是将操作附加到主幻灯片图像(或其包装器)的唯一方法,因为galleriffic仍然在移除和附加这些结构。
https://stackoverflow.com/questions/9193215
复制相似问题