夥計們,我在jquery中遇到了通配符問題。如果可能的話請幫忙。jQuery - 通配符* - 緩存
我正在使用jQuery像函數綁定點擊一個id例如。 proceed_10,proceed_11。現在,如果我點擊proceed_10第一次一切工作正常。但是,如果我再次點擊一個帶有id的圖像作爲proceed_10,那麼它將執行兩次。然後,如果我點擊其他一些圖片,則繼續執行三次。這裏是一個小的代碼片段回顧:
$("[id*='applybut_']").live('click',function(){
var idfinder = null; var currid = null;
idfinder = $(this).attr('id').split('_');
currid = idfinder[1];
$.ajax({
url: "someurl",
type: 'POST',
dataType: 'json',
data: {},
error: function(data){ },
success: function(data){
if(data.success == true)
{
messyhtml+= '<img src="'+proceedimgsrc+'" id="proceed_'+currid+'" style="cursor:pointer;">';
$("[id*='proceed_']").live('click',function(){
var foostr = $(this).attr('id').split('_');
var fooid = foostr[1];
var barid = $('input[name="bar_id"]:checked').val();
if(fooid != '' && barid != '') //This loops executes twice,thrice, and so on...
{
$.ajax({
url: "someurl",
type: 'POST',
dataType: 'json',
data: {'fooid':fooid,'barid':barid},
error: function(data){ },
success: function(data){
if(data.success == true) {
//
} else if(data.success == false) {
//
}
}
});
}
});
$(".popcontainer").html(messyhtml);
}
}
});
});
謝謝Holie,我意識到我錯過了殺害老的現場活動。 – 2012-01-13 05:45:26
謝謝阿曼。讚賞會讚賞,但那不是我在這裏的原因:) – 2012-01-13 20:01:38