2017-03-02 79 views
1

在這個隱藏字段中有一個css類「NSE_View_Delete」。附加如何將css類動態添加到mvc中的隱藏字段使用jquery

我想改變和追加動態等CSS類..

@Html.Hidden("ViewGroupDetails", Url.Action("ViewGroupDetails", "NSEDownload", new { acid = InsiderTrading.Common.ConstEnum.UserActions.NSEDownload }), new { @class = "gridtypecontrol", ctrtype = "link", gridcolumntype = @ViewBag.GridType + "_usr_grd_11073", param = "{'text':'','href':'" + Url.Action("ViewGroupDetails", "NSEDownload", new { acid = InsiderTrading.Common.ConstEnum.UserActions.NSEDownload }) + "&GroupId=<GroupId>','class':'NSE_View_Delete','text':'View/Delete'}" }) 
if (obj.aData['nse_grd_50431'] != null) { 
    var abc = obj.aData['nse_grd_50431']; 
    if (abc == 0) { 
    $('#ViewGroupDetails').addClass('loading123').removeClass('NSE_View_Delete'); 
    } 

瀏覽器中呈現如下的隱藏字段:

<a href="/NSEDownload/ViewGroupDetails?acid=223&amp;GroupId=773" class="NSE_View_Delete">View/Delete</a> 

我怎樣才能做到這一點?

+1

你有什麼應該工作的罰款。請注意,HTML源不會在「查看源代碼」窗口中更改 - 您需要改爲在DOM Inspector中查看更改。 –

+0

您只顯示href,而不是全部隱藏字段。另外 - 你的視圖中只有一個隱藏字段嗎? –

+0

你在$(document).ready(...)中運行你的jQuery代碼嗎? –

回答

0

爲了設置使用jQuery你可以試試這個元素的class屬性:

$("#elementId").removeClass("removed-css-class"); //first remove the class 
$("#elementId").addClass("added-css-class"); //then set classs 

希望這有助於...

相關問題