使用JQuery来检查元素是否有边框? [英] Use JQuery to check if element has a border?

查看:878
本文介绍了使用JQuery来检查元素是否有边框?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

所以我在玩 $(el).css(),试图确定一个元素是否有边框。我使用 .css(border-style,solid)来设置边框,但实际上它设置了4种单独的样式:

So I'm playing with $(el).css(), trying to determine if an element has a border. I use .css("border-style", "solid") to set the border, which works, but actually it sets 4 individual styles:

border-right-style
border-left-style
border-top-style
border-bottom-style

所以,检查一个边框是有点麻烦,因为你必须做一些事情:

So, checking for a border is a bit cumbersome as you have to do something like:

if ($(el).css("border-right-style") == "solid" && $(el).css("border-left-style") == "solid" && ...) {}


b $ b

只需检查 $(el).css(border-style)!=

有更优雅的方式吗?

推荐答案

border-style 是Shorthand,你不能让他们在一起,所以你必须让他们分开,因为根据 Jquery CSS文档

border-style is Shorthand and you cant get them together so you have to get them separatly, because As per Jquery CSS documentation

Shorthand CSS properties (e.g. margin, background, border) are not supported.
For example, if you want to retrieve the rendered margin, 
use: $(elem).css('marginTop') and $(elem).css('marginRight'), and so on.

这篇关于使用JQuery来检查元素是否有边框?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆