【发布时间】:2014-01-14 21:31:22
【问题描述】:
这让我发疯,我尝试了多种方法,但没有任何效果。有没有 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>
【问题讨论】:
-
控制台显示什么错误?
-
未捕获的类型错误:无法读取未定义的属性“marginBottom”
-
.style.marginBottom是纯 JavaScript,您将 jQuery 对象传递给它。 -
如何检查元素 CSS 是否是 jQuery 中的某个值?我只看到了如何设置它。
-
阅读手册即可。 api.jquery.com/css $(wnd).css("margin-bottom");// 以px结尾