我有一个链接,它发布一些数据到一个控制器。它工作正常,并更新了数据。但是我想要更改父div的css,但是没有实现。我尝试了很多变种,但我一定是在做一些愚蠢的事情。
代码如下
查看:
@foreach (var item in Model)
{
<div class="added-property-excerpt">
...
<div class="added-property-links">
...
@if (!item.IsPropertyDisabled) {
@Html.ActionLink("Take off the Market" , "Disable", "Property", new { id = item.PropertyId }, new { id ="disable-link" })
}
else {
@Html.ActionLink("Bring on the Market" , "Enable", "Property", new { id = item.PropertyId }, new { id ="enable-link" })
}
</div>
</div>
}JQuery
<script>
$(function () {
$('a#disable-link').click(function (e) {
$('.added-property-links').text('loading...');
$.ajax({
url: this.href,
dataType: "text json",
type: "POST",
data: {},
success: function (data, textStatus) { }
});
$(this).closest('.added-property-excerpt').css("background", "red");
// $(this).parent('.added-property-excerpt').css("background", "red");
e.preventDefault();
});
});
</script>发布于 2012-10-14 08:49:41
尝尝这个
$(function () {
$('a#disable-link').click(function (e){
var parentDiv=$(this).closest('.added-property-excerpt');
$('.added-property-links').text('loading...');
parentDiv.css("background", "red");
$.ajax({...});
e.preventDefault();
});
});查看和之间的区别。
发布于 2012-10-14 08:19:47
你有没有尝试:
$(this).parents('.added-property-excerpt').css("background", "red");具有%s的parents。
它所做的就是从一个父类到另一个父类,直到它找到你想要的类。
https://stackoverflow.com/questions/12878215
复制相似问题