2014-07-10 90 views
-1

引導鍵單擊事件li單擊事件未觸發。我的代碼是:引導鍵單擊事件

<ul class="typeahead dropdown-menu" style="top: 43px; left: 576.5px; display: none;"> 
    <li class="tyli" data-value="Thana Thana"> 
    <li class="tyli active" data-value="Thiline Lesin"> 
    <li class="tyli" data-value="Thani Taruwe"> 
    <li class="tyli" data-value="Thotupala Aine"> 
    <li class="tyli" data-value="Tharu Wiyane"> 
    <li class="tyli" data-value="Tholata Mala"> 
    <li class="tyli" data-value="Thaama Tharunai"> 
    <li class="tyli" data-value="Thana Thinane"> 
</ul> 
$('.dropdown-menu').on('click','li', function(){  
    alert('Hello');  
}); 

名單是動態的頁面加載後它就會出現。 我的JavaScript代碼在頁面加載後添加。

這裏有什麼不對嗎?

+0

如何在提問中添加小提琴和/或添加html和javascript代碼? – webdad3

+0

嗨webdad3,我的代碼編輯。 – chamaraherath

+0

做什麼Cerebus1504建議。去getbootstrap.com。那裏有很多例子。 – webdad3

回答

3

這應該是一個適合您的例子。如果你想在bootstrap上工作,getbootstrap.com將會超過無奈

<!DOCTYPE html> 
    <html lang="en"> 

<head> 
    <meta charset="utf-8"> 
    <meta name="viewport" content="width=device-width, initial-scale=1.0"> 
    <meta name="description" content=""> 
    <meta name="author" content=""> 

    <title>Start Bootstrap Template</title> 

    <!-- Bootstrap core CSS --> 
    <link href="css/bootstrap.css" rel="stylesheet"> 

    <!-- Add custom CSS here --> 

    <link href="font-awesome/css/font-awesome.min.css" rel="stylesheet"> 
    <script src="js/jquery-1.10.2.js"></script> 
    <script src="js/bootstrap.js"></script> 
</head> 

<body> 

    <nav class="navbar navbar-inverse navbar-fixed-top" role="navigation"> 
     <div class="container"> 
      <div class="navbar-header"> 

       <a class="navbar-brand" href="index.html">Sample</a> 
      </div> 

      <div class="collapse navbar-collapse navbar-ex1-collapse"> 
       <ul class="nav navbar-nav navbar-right"> 

        <li class="dropdown"> 
         <a href="#" class="dropdown-toggle" data-toggle="dropdown">Portfolio <b class="caret"></b></a> 
         <ul class="dropdown-menu"> 
          <li><a href="portfolio-1-col.html">1 Column Portfolio</a> 
          </li> 
          <li><a href="portfolio-2-col.html">2 Column Portfolio</a> 
          </li> 
          <li><a href="portfolio-3-col.html">3 Column Portfolio</a> 
          </li> 
          <li><a href="portfolio-4-col.html">4 Column Portfolio</a> 
          </li> 
          <li><a href="portfolio-item.html">Single Portfolio Item</a> 
          </li> 
         </ul> 
        </li> 
        <li class="dropdown"> 
         <a href="#" class="dropdown-toggle" data-toggle="dropdown">Blog <b class="caret"></b></a> 
         <ul class="dropdown-menu"> 
          <li><a href="blog-home-1.html">Blog Home 1</a> 
          </li> 
          <li><a href="blog-home-2.html">Blog Home 2</a> 
          </li> 
          <li><a href="blog-post.html">Blog Post</a> 
          </li> 
         </ul> 
        </li> 
        <li class="dropdown"> 
         <a href="#" class="dropdown-toggle" data-toggle="dropdown">Other Pages <b class="caret"></b></a> 
         <ul class="dropdown-menu"> 
          <li><a href="full-width.html">Full Width Page</a> 
          </li> 
          <li><a href="sidebar.html">Sidebar Page</a> 
          </li> 
          <li><a href="faq.html">FAQ</a> 
          </li> 
          <li><a href="404.html">404</a> 
          </li> 
          <li><a href="pricing.html">Pricing Table</a> 
          </li> 
         </ul> 
        </li> 
       </ul> 
      </div> 
      <!-- /.navbar-collapse --> 
     </div> 
     <!-- /.container --> 
    </nav> 

    </div> 
    <!-- /.container --> 

    <!-- JavaScript --> 

</body> 

</html>