如何从 Style DOM 对象获取源文件行号?

发布于 2024-12-12 02:10:13 字数 163 浏览 0 评论 0原文

我是 JavaScript 世界的新手。如果您检查 Chrome 浏览器的开发人员工具的“元素”选项卡的右窗格,您将找到“匹配的 css 规则”部分,其中显示了源文件名,并且对于每个应用的 css 规则,显示了行号。

我的问题是,HTML DOM 的哪些对象属性可以告诉行号(和源文件名)?谢谢!

I'm new to JavaScript world. If you check in the Chrome browser's Developer tools the right pane of the Element tab, you'll find the 'Matched css rules' section, there is a source file name shown and for each applied css rule there is the line number shown.

My question is, which object properties of the HTML DOM can tell the line numbers (and the source file name) ? Thanks!

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

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

发布评论

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

评论(1

疾风者 2024-12-19 02:10:13

阅读整个第一个([0])样式表...

var a;
for (var i=0; i<document.stylesheets[0].cssRules.length; i++)
{
 a = document.stylesheets[0].cssRules[i]+'\n';
}

alert(a);

您应该能够通过行号来提醒规则,我想虽然这完全没用,但您想要引用一个元素并找出什么规则( s) 改为应用于它。

更多信息请参见:http://www.javascriptkit.com/dhtmltutors/externalcss3.shtml

Read the entire first ([0]) style sheet...

var a;
for (var i=0; i<document.stylesheets[0].cssRules.length; i++)
{
 a = document.stylesheets[0].cssRules[i]+'\n';
}

alert(a);

You should be able to alert a rule by a line number I imagine though that would be utterly useless, you'd want to reference an element instead and figure out what rule(s) applied to it instead.

More here: http://www.javascriptkit.com/dhtmltutors/externalcss3.shtml

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