这是代码:
<!DOCTYPE html>
<html>
<head>
<title>Pixgalery</title>
<link rel="shortcut icon" href="/favbar.png" />
<link rel='stylesheet' href='/stylesheets/style.css'/>
<!-- JavaScript -->
<script src="http://code.jquery.com/jquery-latest.js"></script>
<script type="text/javascript">
alert($('#fh'));
</script>
<script src="/stylesheets/bootstrap/js/bootstrap.min.js"></script>
<!-- CSS -->
<link href="/stylesheets/bootstrap/css/bootstrap.min.css" rel="stylesheet"
media="screen">
<link href="/stylesheets/bootstrap/css/bootstrap.css" rel="stylesheet" media="screen">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link href="/stylesheets/bootstrap/css/bootstrap-responsive.css" rel="stylesheet">
<style type="text/css">
body {
<% if(user.background == ''){ %>
background: rgb(241, 241, 241) url('/noise_filter.png');
<% } else {%>
background: url('.<%= user.paths %><%= user.background %>') fixed;
<% } %>
}
</style>
</head>
<body>
<div class="navbar-static-top navbar-inverse navbar">
<div class="navbar-inner">
<div class="container">
<a class="btn btn-navbar" data-toggle="collapse" data-target=".nav-collapse">
<span class="icon-bar"></span>
<span class="icon-bar"></span>
<span class="icon-bar"></span>
</a>
<a class="brand" href="#">Pixgalery</a>
<div class="nav-collapse collapse">
<ul class="nav">
<li><a href="/home">Home</a></li>
<li><a href="/<%= req %>">Profile</a></li>
<li><a href="#">Messages</a></li>
</ul>
<ul class="nav pull-left">
<form class="navbar-search pull-left">
<input type="text" class="search-query" placeholder="Search...">
</form>
</ul>
</div>
</div>
</div>
</div>
<div style="margin-top: 15px;" class="container-fluid">
<div class="row-fluid">
<div class="span1"></div>
<div class="span6">
</div>
</div>
<div class="span4">
<aside>
<center><h2 style="margin-top: 0px;"><%= photo.author %></h2></center>
<table style="margin-top: 5px" class="table">
<tbody style="background: white;">
<tr>
<td>
<h4>Views <small><%= photo.views %></small></h4>
</td>
</tr>
<tr>
<td>
<h4>Favourites <small><%= photo.fav %></small></h4>
<button class="btn btn-inverse" id="fh">
<i style="margin-right: 5px;" class="icon-heart icon-white"></i>
Favorite</button>
</td>
</tr>
<tr>
</tr>
</tbody>
</table>
</aside>
</div>
</div>
</div>
</head>
</body>
当我收到警报alert($('#fh'))
时,警报会显示给我[object Object]
,或者即使我收到了,我也会alert(document.getElementById('fh')
收到null
,因此,我无法通过诸如click()
. 当我输入控制台`$('#fh')'时,我得到了元素,但我不知道为什么,例如这不起作用:
$('#fh').click(function(){
alert('alert!');
})
我该如何解决这个...?
谢谢提前!