jQuery 插件 if else 子句不起作用?
我正在编写一个 jQuery 插件,我正在尝试这样做:
$(this).height>=options.maxHeight ?
$(this).css({overflow:"auto"}) :
$(this).css({overflow:"hidden"})
但是它不起作用,我之前在我的 javascript 中使用过这个方法。
这应该如何工作,只是我试图使用尽可能少的代码。
if($(this).height()>=options.maxHeight)
{
$(this).css({overflow:"auto"});
}
else
{
$(this).css({overflow:"hidden"});
}
I'm writing a jQuery plugin and I am trying to do this:
$(this).height>=options.maxHeight ?
$(this).css({overflow:"auto"}) :
$(this).css({overflow:"hidden"})
however it's not working, I have used this method in my javascript before.
This works how it should, just i was trying to use little code as possible.
if($(this).height()>=options.maxHeight)
{
$(this).css({overflow:"auto"});
}
else
{
$(this).css({overflow:"hidden"});
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
将其更改为:
您忘记了
.height()
中的()
。你也可以使用这个:
Change it to:
You forgot the
()
in.height()
.You could also use this: