我有这个jQuery的文件,但vote_up click handler
保持与vote_down click handler
发生冲突,当我点击它改变了vote_up元素vote_down元素:jQuery的 - 点击一个元素上触发另一个
jQuery脚本:
$(document).ready(function() {
$("a.vote_up").click(function() {
//get the id
var the_id = this.id.split('_').pop();
//the main ajax request
$.ajax({
type: "POST",
data: "action=vote_up&id=" + the_id,
url: "ajax/votes.php",
success: function (msg) {
$("span.vote_count#" + the_id).html(msg).fadeIn();
$("#" + the_id + " img").attr("src", "img/uparrowActive.png");
}
});
});
});
$(document).ready(function() {
// the vote down function
$("a.vote_down").click(function() {
//get the id
var vote_id = this.id.split('_').pop();
//the main ajax request
$.ajax({
type: "POST",
data: "action=vote_down&id=" + vote_id,
url: "ajax/votes.php",
success: function (msg) {
$("span.vote_count#" + vote_id).html(msg).fadeIn();
$("#" + vote_id + " img").attr("src", "img/downarrowActive.png");
}
});
});
});
HTML:
<a href='#' class='vote_up' id="id_23"><img src="img/uparrow.png" /></a>
<a href='#' class='vote_down' id="id_23"><img src="img/downarrow.png" /></a>
了jQuery和Ajax请求工作呢罚款,但SRC的变化是问题,因为当我点击否决,我t改变了vote_up图像!
所有这些都可以进入'$(document).ready()' – colinmarc 2010-10-05 23:25:56
逍遥游 - 请参阅@ Pointy的回答并记住它。在您之前的问题中已经提到过很多次。这是一个不容忽视的重要规则。对不起,很生硬。 – user113716 2010-10-05 23:27:03
对不起,我只是很困惑,这是我为我的大学项目,所以我必须得到它的权利,即时通讯这样的新手:)) – getaway 2010-10-05 23:28:22