Ton*_*y R 6 html javascript css jquery border
所以我正在玩$(el).css(),试图确定一个元素是否有边框.我.css("border-style", "solid")用来设置边框,它有效,但实际上它设置了4个单独的样式:
border-right-style
border-left-style
border-top-style
border-bottom-style
Run Code Online (Sandbox Code Playgroud)
因此,检查边框有点麻烦,因为您必须执行以下操作:
if ($(el).css("border-right-style") == "solid" && $(el).css("border-left-style") == "solid" && ...) {}
Run Code Online (Sandbox Code Playgroud)
简单地检查$(el).css("border-style") != ""不起作用,因为border-style总是等于"".
有没有更优雅的方式来做到这一点?
border-style是速记,你不能把它们放在一起所以你必须分开得到它们,因为根据Jquery CSS文档
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.
Run Code Online (Sandbox Code Playgroud)