1
我有以下佈局:找到最接近的元素
<div class="widgets">
<div class="rating_block">
<span class="iFoot fMin"><%= film.GoingCount %></span>
<div class="stars_rating">
<div class="stars_off"></div>
<div class="stars_on"></div>
</div><!-- .stars_rating-->
<span class="num_rating">(<%= film.Rating %>)</span>
<div class="expand"></div>
</div><!-- .rating_block-->
<div class="voice_block">
<div class="going" filmid="<%=film.OID %>">
<a href="">I'm going!</a>
<div id="going_too">Going too: <%= film.GoingCount %></div>
</div><!-- .going-->
<div class="data_for_rating">
<div>Vote</div>
<div class="star_for_rating">
<ul>
<li>
<a href="#">1</a>
</li>
<li>
<a href="#">2</a>
</li>
<li>
<a href="#">3</a>
</li>
<li>
<a href="#">4</a>
</li>
<li>
<a href="#">5</a>
</li>
</ul>
</div><!-- .star_for_rating-->
<div>Average: 4,5 (89)</div>
</div><!-- .data_for_rating-->
</div><!-- .voice_block-->
</div><!-- .widgets-->
我的js函數:
function setUpUpdateGoingCount() {
$("div.going a").click(function (e) {
var goingToo = $(this);
e.preventDefault();
var filmId = $(this).parent("div").attr("filmid");
$.post("/Cinema/UpdateGoingCount", { id: filmId }, function (obj) {
if (obj.Success) {
goingToo.parent("div").find("#going_too").text("going too: " + obj.Result); //work
goingToo.closest(".rating_block").find(".iFoot.fMin").text(obj.Result); //not work
}
});
});
};
爲什麼jQuery的不能找到span
與iFoot.fMin
類? 我正在使用closest
,因爲此塊(widget
)可能是幾個。
謝謝,它的工作。但我認爲這更好:goingToo.closest(「。widgets」)。find(「。iFoot.fMin」)。text(obj.Result); – user348173 2011-12-21 11:03:37
假設'.widgets'不包含幾個評級和語音模塊,在這種情況下,我會使用我建議的解決方案。 – 2011-12-21 11:05:42