簡體   English   中英

jQuery通過類單擊更改CSS

[英]jQuery Change CSS via Class Click

這讓我發瘋,我已經嘗試了多種方法,但沒有任何效果。 有jQuery上帝能幫助我嗎?

jQuery的:

$(".FCChatControl").click(function(event) {
    var id = $(this).attr("rel");
    var wnd = $(id);
    if (wnd.style.marginBottom == "-1px") {
        $(wnd).css({"margin-bottom": "-236px"});
    } else {
        $(wnd).css({"margin-bottom": "-1px"});
    }
});

執行自:

<a href="javascript:void(0)" rel="#item.OwnerID#" id="FCChatControlID" class="FCChatControl">
    <div id="cw-header">
        <h1>#item.Nickname#</h1>
    </div>
</a>

目前尚不清楚您要做什么,但是現在您需要檢查CSS屬性並對其進行操作。

http://jsfiddle.net/isherwood/DxNA3/

$('.FCChatControl').click(function() {
    if ($(this).css('margin-bottom') == "-1px") {
        $(this).css('margin-left', '50px'); // demo
    }
});

順便說一句,您的else子句似乎毫無意義,因此已將其刪除。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM