2010-08-17 96 views
0

我有加载引号的页面。它有一个搜索表单,如果用户键入搜索关键字,它将通过ajax加载结果。现在,如果我点击应该使用引号加载默认页面的链接,而不是搜索结果页面,则什么都不会发生。jQuery加载默认页面问题

如果我在家里/默认页面上,点击链接,它会显示一个随机引用,但是一旦显示了搜索页面,如果我点击链接显示一个随机引用,什么都不会发生。 Firebug显示该功能未被执行。

jQuery代码:

  function loadQuotes() { 
       $("#bquote").load("quotes_in.php"); 
} 

    $("a#main").click(function() { 
       $(this).addClass("current"); 
       $(".toggleDiv").slideUp(600); 
        loadQuotes(); 
       }); 
       loadQuotes(); //call it once on load 

      $(".bsearch").keydown(function() { 
        //create post data 
         var postData = { 
         "search" : $(this).val() 
         }; 

         //make the call 
         $.ajax({ 
         type: "POST", 
         url: "quotes_in.php", 
         data: postData, //send it along with your call 
         success: function(response){ 
           setTimeout(function() { 
           $('#left').html(response); 
            $("div#smore").hide(); 
           }, 250);  

         } 
         }); 

       }) 

HTML:

   <!-- Begin Left Column --> 
       <div id="left"> 
        <!-- Begin Panel --> 
        <div class="check"> 
     <p><input type="checkbox" value="Quote" name="quote" id="quote" checked /> <label for="quote">Quote</label></p> 
    <p><input type="checkbox" value="Reference" name="reference" id="reference" checked /> <label for="reference">Reference</label></p> 
      </div> 
     <!-- End Panel --> 
      <!-- Begin Quote --> 
     <blockquote id="bquote"> 
     </blockquote> 
               <!-- End Quote --> 

             </div> 
           <!-- End Left Column --> 

    <!-- Begin Naviagtion --> 
     <div id="navigation"> 

      <ul> 
       <li><a id="main">Another?</a></li> 
       <li><a id="bsearch">Search</a></li> 
       <li><a id="babout">About</a></li> 
       <li><a id="bcontact">Contact</a></li> 
      </ul> 

     </div> 
     <!-- End Naviagtion --> 

PHP搜索:

public function formatSearch($row, $search) 
      { 
       $cQuote = $this->highlightWords(htmlspecialchars($row['cQuotes']), $search); 

        return "<div class=\"swrap\">" 
       . "<p id=\"s_quotes\"><img src=\"image/list1.png\" alt=\"b\" style=\"position:relative; top:2px;\">&nbsp;" . $cQuote . "&nbsp;</p>" 
       . "<div id=\"smore\"><p id=\"s_arabic\">" . $this->h($row['cArabic']) . "</p>" 
       . "<p id=\"s_author\"><b>~</b>&nbsp;" . $this->h($row['vAuthor']) . "</p>" 
       . "<p id=\"s_reference\"><span class=\"source\">Source:</span> " . $this->h($row['vReference']) . "</p></div></div>" 
       . "<img src=\"image/sep.png\" style=\"position:relative; left: 600px;\">"; 
      } 

回答

1

新的结果都不会由JavaScript被公认的唯一的脚本确认页面加载时有什么HTML。为了能够“看见”通过AJAX功能生成的HTML你的功能,你需要使用jQuery的,他住的功能http://api.jquery.com/live/

转换目前的点击功能,这样的事情

$('a#main').live('click', function() { 
    $(this).addClass("current"); 
      $(".toggleDiv").slideUp(600); 
       loadQuotes(); 
});