任何人都可以解釋爲什麼這個jQuery .html()
函數不輸出任何東西? 我是新太jQuery和着縫發現任何東西,如果你能告訴我:djQuery中的.html()函數問題
我就包括HTML,沒有別的:
<script type="text/javascript" src="jquery-1.3.2.min.js"></script>
<script type="text/javascript" src="jquery.scrollTo-1.4.2.js"></script>
<script type="text/javascript">
//when the DOM is ready
$(document).ready(function(){
var like_count = <?php print "23"; ?>;
//Scripts for getting number of comments for this post
var comment_count = <?php print "12"; ?>
var thumnail_path - "";
var time_ago - "";
//settings on top
var doindex = 'comments.php?item_id=';
var initialPosts = <?php echo get_posts(0,$_SESSION['posts_start']); ?>;
//function that creates posts
var postHandler = function(postsJSON) {
$.each(postsJSON,function(i,post) {
//post url
var postURL = '' + doindex + post.item_id;
var id = 'post-' + post.ID;
//create the HTML
$('<div></div>')
.addClass('post')
.attr('id',id)
//Script for getting the number of likes for this post
//generate the HTML
.html('<table width="244" height="121" border="0" cellpadding="0" cellspacing="2" ><tr><td height="24" colspan="2" bgcolor="#0270B7"><table width="410" border="0"><tr> <td width="404" height="20" class="username"><a href="../profile.php?user=' + post.username + '" class="username"> ' + post.username + '<span class="name"> ' + post.name + '</span></a></td></tr></table></td></tr><tr> <td width="51" bgcolor="#Edeff4"><span class="thum"><img src="' + thumnail_path + '" alt="" width="50" height="50" /></span></td><td width="355" height="50" bgcolor="#Edeff4" class="content"> ' + post.item_content + '</td></tr><tr><td height="19" colspan="2" bgcolor="#Edeff4" class="content"><a href="comment.php?id=' + post.item_id + '" class="post-title"> <span class="post-title">comment </span></a><a href="#" class="post-title">(' + likecount + '</a><a href="comment.php?id=' + post.item_id + '" class="post-title"><span class="post-title">)</span></a> <span class="post-title"><a href="#" class="post-title">likes (' + likecount + ') ' + time_ago + '</a></span></td></tr><tr><td height="18" colspan="2" class="content"> </td></tr></table>')
謝謝:))
什麼是你調用'.html()'?當然,這一定是某種東西。 – aroth 2011-03-27 03:17:32
你需要把內容放入''('#someDiv')。html('
');'http://api.jquery.com/html/ – EmCo 2011-03-27 03:18:18Javascript應該*操作* DOM ,而不是創建它。你到底在做什麼把標記放在腳本方法中? – 2011-03-27 03:18:51