Bootstrap typeahead 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 :(得分:2)
这应该是一个适合你开始的例子。如果你想在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>