我遇到了以下問題: 我似乎無法保留我在每個重複項目中選擇的鏈接。 「這個」這個詞正在迷失。 Var event_id適用於每個元素,但var $ something是未定義的? 這是爲什麼呢,理想情況下,我想做一個switch語句,但同樣的問題,似乎無法讓它知道我點擊了什麼鏈接以及它周圍的元素來執行操作。jquery範圍問題
更新全功能:
function rsvp (selector,function_url) {
$(selector).livequery('click',function(){
var $select = $(selector).attr('rel');
var $event_id= $(this).parents('ul.event-options').attr('rel');
if ($select == "attending") {
$(this).closest('span.rsvp-status').html("I'm Attending – <a href='javascript:;' class='remove' rel='remove'>Remove</a>");
var $something = $(this).parents('ul.event-options').attr('rel');
alert($something);
}
if ($select == "remove") {
$(this).closest('span.rsvp-status').html("Not Attending – <a href='javascript:;' class='rsvp' rel='attending'>RSVP?</a>");
}
if ($select == "interested") {
$(this).closest('li').addClass('interested');
$(this).closest('li').removeClass('not-interested');
$(this).closest('li').html("You're Interested");
}
$.ajax({
type: "POST",
url: "/events/set_member/"+function_url,
data: "event_id="+$event_id,
beforeSend: function() {
$("<span class='notice'>Updating...</span>").prependTo('body');
},
complete: function()
{
$('span.notice').fadeOut(500);
}
});
});
}
rsvp ('a.rsvp','rsvp');
rsvp ('a.interests','interested');
rsvp ('a.remove','remove');
HTML
<ul class="event-options" rel="<?=$event['event_id']?>">
<?php if($event['rsvp_total'] > 0) { ?>
<!-- Show Only When Count is Greater than 0 -->
<li class="group"><span class="total"><?= $event['rsvp_total']?></span>Interested </li>
<?php } ?>
<li class="rsvp"><span class="rsvp-status"> Not Attending – <a href="javascript:;" class="rsvp" rel="attending">RSVP?</a></span></li>
<li class="not-interested"> <a href="javascript:;" class="interests" rel="interested"> Interested? </a> </li>
<li class="place"><span><a href="<?=$place_path.$event['place_id']?>"><?=$event['place_name']?></a></span></li>
<li class="share" rel="<?=$event['event_name']?>">
<a class="sharethis"></a>
</li>
</ul>
新增,忽略php – matthewb 2009-10-14 17:41:39