2014-03-25 80 views
-1

我正在編寫分頁腳本,除了一個小問題之外,所有這些都很好。我需要點擊頁碼(li)時觸發一個動作。jQuery爲分頁選擇li

分頁通過ajax返回到稱爲「結果」的div。然而,這個div深深烙上了其他幾個div--我認爲這可能是問題所在。如何解決?

感謝

$('#result .pagination li').live('click', function() { 
     var page = $(this).attr('p'); 
     loadData(page); 
     return false; 
    }); 

完整的輸出低於與全分頁

<body> 
<div id="wrapper"> 
    <nav class="navbar navbar-default navbar-static-top" style="margin-bottom: 0"> 
     <div class="navbar-header"> 
      <button class="navbar-toggle" type="button"><span class="sr-only">Toggle navigation</span> 
      </button> <a class="navbar-brand" href="index.php">Title</a> 
     </div> 
    </nav> 
    <nav class="navbar-default navbar-static-side"> 
     <div class="sidebar-collapse"> 
      <ul class="nav" id="side-menu"> 
       <li class="sidebar-search"> 
        <div class="input-group custom-search-form"> 
         <input class="form-control" placeholder="Search..." type="text"> 
        </div> 
        <!-- /input-group --> 
       </li> 

       <li class="active"><a href="index.php">Dashboard</a> 
       </li> 

       <li><a href="claims.php">Claims</a> 
       </li> 
      </ul> 
     </div> 
    </nav> 

    <div id="page-wrapper"> 
     <div class="row"> 
      <div class="col-lg-12"> 
       <h1 class="page-header">Claims</h1> 
      </div> 
     </div> 

     <div class="row"> 
      <div class="col-lg-12"> 
       <div class="panel panel-default"> 
        <div class="panel-heading"> 
         DataTables Advanced Tables 

         <div id="loading" style="float: right; display: none;"> 
          <img src="images/loading.gif"> 
         </div> 
        </div> 

        <div class="panel-body"> 
         <div id="result"> 
          <!-- DATABASE RESULTS GO HERE --> 
          <ul class="pagination" id="pg"> 
           <li class="disabled"><a href="#">First</a> 
           </li> 

           <li class="disabled"><a href="#">«</a> 
           </li> 

           <li class="disabled"><a>1</a> 
           </li> 

           <li><a href="#">2</a> 
           </li> 

           <li><a href="#">3</a> 
           </li> 

           <li><a href="#">4</a> 
           </li> 

           <li><a href="#">5</a> 
           </li> 

           <li><a href="#">6</a> 
           </li> 

           <li><a href="#">7</a> 
           </li> 

           <li><a href="#">»</a> 
           </li> 

           <li><a href="#">Last</a> 
           </li> 
          </ul> 
         </div> 
        </div> 
       </div> 
      </div> 
     </div> 
    </div> 
</div> 

我使用jQuery v1.10.2的

+1

可以分享html ...還有什麼是jQuery版本使用 –

+0

嗨補充,謝謝 – user3163357

回答

1

您正在使用jQuery> = 1.9 ,所以有no .live() method

$(document).on('click', '#result .pagination li', function() { 
    var page = $(this).attr('p'); 
    loadData(page); 
    return false; 
});