我有一个页面中,我一直职位和用户,发表意见。该意见正在使用AJAX来处理。每个注释行有一个投票按钮。
I've a page in which I've posts and users are to give comments. The comments are handled using AJAX. Each comment line has a "Vote" button.
在索引页,我已经把jQuery函数的投票
In the index page, I've put the jQuery function for the vote
<script type="text/javascript">
$(function() {
$('.voteUpBtn').click(function() {
// Cast your vote
}
}
</script>
现在,当用户提交一个新的注释,它使AJAX调用并追加使用jQuery到索引页面的HTML
Now when a user submits a new comment, it makes an AJAX call and appends the HTML using jQuery to the index page
$.ajax({
type: "POST",
url: "proc/add-line.php",
data: dataString,
cache: false,
success: function(html){
$("ul#nextLines").append(html);
}
});
在附加的HTML,我也有同样的投票按钮。 (每个注释都有一个相应的投票按钮)。
On the appended HTML, I have the same vote button. (Each comment has a corresponding vote button).
现在的问题是,由AJAX生成的新注释的投票按钮不起作用。如果我刷新页面,投票工作(虽然我使用了相同的标记)。
The Problem is, the "vote" button on the new comment generated by AJAX doesn't work. If I refreshed the page, the vote works (although I'm using the same Markup).
我怎么有可能使投票按钮在AJAX工作返回的HTML ??
How do I make it possible for the vote button to work in the AJAX returned HTML??
使用生活
而不是点击
:
$('.voteUpBtn').live('click', function() {
// Cast your vote
}