2011-07-05 43 views
0

我想用AJAX和.live(),所以我可以讓事情變得整潔。我想知道它是如何完成的,我已經提供了一個基本功能:在一個按鈕上單擊一個標籤放置在一個。但我需要使用live()才能在該圖像上使用lightbox。JQUERY住在AJAX

$(document).ready(function() 
{ 
    $("button").click(function() 
    { 
     $("div").load('test1.txt') 
    }); 
}); 

燈箱廣告:

$(function() 
{ 
    $('#gallery a').lightBox(); 
}); 

CSS:

<style type="text/css"> 
    /* jQuery lightBox plugin - Gallery style */ 
    #gallery 
    { 
     background-color: #444; 
     padding: 10px; 
     width: 520px; 
    } 

    #gallery ul 
    { 
     list-style: none; 
    } 

    #gallery ul li 
    { 
     display: inline; 
    } 

    #gallery ul img 
    { 
     border: 5px solid #3e3e3e; 
     border-width: 5px 5px 20px; 
    } 

    #gallery ul a:hover img 
    { 
     border: 5px solid #fff; 
     border-width: 5px 5px 20px; 
     color: #fff; 
    } 

    #gallery ul a:hover 
    { 
     color: #fff; 
    } 
</style> 

用法: 使用id =畫廊div標籤

HTML: 
<link rel="stylesheet" type="text/css" href="../style-projects-jquery.css" />  

    <script type="text/javascript" src="js/jquery.js"></script> 
    <script type="text/javascript" src="js/jquery.lightbox-0.5.js"></script> 
    <link rel="stylesheet" type="text/css" href="jquery.lightbox-0.5.css" media="screen" /> 

<h2 id="example">Example</h2> 
<p>Click in the image and see the <strong>jQuery lightBox plugin</strong> in action.</p> 
<div id="gallery"> 
    <ul> 
     <li> 
      <a href="photos/image1.jpg" title="Utilize a flexibilidade dos seletores da jQuery e crie um grupo de imagens como desejar. $('#gallery').lightBox();"> 
       <img src="photos/thumb_image1.jpg" width="72" height="72" alt="" /> 
      </a> 
     </li> 
</ul> 
</div> 

如果有人能幫助我改變。點擊()函數...

+0

你可以發佈你的HTML嗎? – Kokos

回答

1

使用的回調:

$(function(){ 

    $('button').live('click', function() { 
     $('div').load('test1.txt', function() { 
      $('#gallery a').lightBox(); 
     }); 
    }); 

}); 
+0

如何使用此回調函數? –

+0

正如上面所示:.load() –

+0

如果我替換\t <腳本類型= 「文本/ JavaScript的」> \t $(文件)。就緒(函數(){ \t \t $( 「鏈接」) 。點擊(函數(){ \t \t \t \t $( 「DIV」)負載( 'test1.txt的')。}); \t}); 與您的功能...我得到一個錯誤...:| –

1

jQuery的生活()不能在自定義事件中使用,文件準備好,或者任何插件調用。

你必須再次在ajax輸出中調用插件才能正常工作。

+0

我只想使用ajax來加載圖像,並且應用程序將lightbox,I am open想法... –