我有一個Galleriffic,一個流行的jQuery插入顯示與他們附近的HTML圖像的問題。Galleriffic:它加載之前我的jquery代碼,其中的對象內部加載
在該HTML,我有一個圖像,用作按鈕:
的<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(){}
事件時沒有按鈕。
有沒有辦法強制Galleriffic加載之前的jQuery代碼?
下面是一些代碼儘可能更加清晰:
<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庫。
我試過了,但在此之前的按鈕出現的「prev_photo」和「next_photo」鏈接,但Galleriffic後剩下的這段時間負載是我的代碼後加載jQuery代碼仍然加載。 Howefer我有//初始化高級Galleriffic圖庫_代替://初始化最小Galleriffic圖庫_和比你的例子更加碼...如果它是有用的...... – 2012-02-08 13:08:54
我已經找到了解決辦法,它不是那麼優雅但它的工作原理。 首先,我把我的jquery代碼放在$(window).load(function() 而不是(document).ready(function($),所以它會在整個頁面加載後運行。 但是當我爲了解決這個問題,我還把Jquery代碼放在Galleriffic函數中,名爲 「function pageload(hash)」,之前就把它放在了Galleriffic的內容中,因爲這個按鈕已經被加載了「返回」聲明,以便在任何時候更改Galleriffic的內容時刷新。 – 2012-02-08 15:08:42
花了整整一個上午和下午的一個下午後,我只希望這對別人有用;) – 2012-02-08 15:08:55