Jquery,获取样式:背景(不是背景颜色)、边框等,无法弄清楚如何做到这一点

发布于 2024-09-11 01:46:28 字数 286 浏览 1 评论 0原文

看来firefox会自动组合一些东西,例如它采用单独的css值,例如“border-color”,“border-width”并将它们全部转储到“border”中。这使得jquery变得很痛苦,因为. css选择器只能选择单个的,例如“边框颜色”,而不仅仅是“边框”或“背景”。我需要获取“边框”或“背景”的完整值,以便我可以解析它以获取我需要的值..我已阅读其他帖子并尝试了以下操作,但它没有返回值:

test = $("#mydiv").attr("border");

任何建议表示赞赏

It seems that firefox automatically combines things, such as it takes individual css values, such as for "border-color", "border-width" and dumps them all into "border".. this makes things a pain for jquery as the .css selector can only select the individual ones, like "border-color", not just "border" or "background".. I need to get the full value of "border" or "background" so that I can parse it to get the values I need.. I have read other posts and have tried the following but its not giving back the value:

test = $("#mydiv").attr("border");

Any advice is appreciated

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

反差帅 2024-09-18 01:46:28

我想你想这样做:

test = $("#mydiv").css("border");

编辑:好的,你可以使用普通的旧 JavaScript:

test = $("#mydiv")[0].style.border

I think you want to do this instead:

test = $("#mydiv").css("border");

EDIT: ok you can use plain old javascript:

test = $("#mydiv")[0].style.border
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文