jQuery 选择器帮助 - 我可以通过单击元素生成选择器吗?
我有 jQuery、FireFox、Firebug、IE 和 IE 开发人员工具栏。当我使用 FireBug 或 IE Dev 工具栏检查页面时,我可以单击一个元素,它会在 dom 中显示该元素的位置等...是否有办法将该选择转换为有效的 jQuery 选择器?我知道我可以使用相对于其他元素的 ID、类和元素等...但是当我查看一些没有类或 id 等的随机表格单元格时该怎么办...我可以在就这样飞?我想肯定有。任何想法或想法总是感激
谢谢, 〜ck在圣地亚哥
I have jQuery, FireFox, Firebug, IE, and IE developer toolbar. When I am examing a page with either FireBug or IE Dev toolbar, I am able to click on an element and it shows me in the dom where the element is etc... Is there anyway to transform that selection into a valid jQuery selector? I know I can use ID, classes, and element relative to other elements etc... but what about when I am looking at some random table cell that doesn't have a class or id etc.. Can I generate a selector on the fly like that? I thought for sure there was. Any thoughts or ideas are always appreciated
Thanks,
~ck in San Diego
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
有一些免费工具可以帮助您找到选择器。一个称为 Selector Detector,另一个称为 SelectorGadget。
两者非常相似并且易于实现。只需为 JavaScript 链接添加书签并在您的网站上打开它(就像 Firebug lite 一样)。然后单击您的元素以显示其选择器。
我刚刚写了一篇文章比较两者,其中包括演示和下载链接。如果您想了解更多信息,请查看此处:http:// /www.heinencreative.com/archives/articles/selector- detector-vs-selectorgadget/
There are a couple of free tools that will help you find your selector. One is called Selector Detector and the other is SelectorGadget.
Both are very similar and easy to implement. Just bookmark a javascript link and open it on your site (just like firebug lite). Then click on your element to display its selector.
I just wrote an article comparing the two that includes demos and download links. If you want to read more, check it out here: http://www.heinencreative.com/archives/articles/selector-detector-vs-selectorgadget/
查看 Firebug 的 FireQuery 插件。
Check out the FireQuery plugin for Firebug.
在 Firebug 中,您可以编写 $1,它是页面上最后选择的对象。
In Firebug you can write $1 which is the last selected object on the page.
如果您想向 DOM 元素添加属性,即使用 Firebug 的
元素,
元素并检查元素。
......这就是全部。
If you're looking to add an attribute to a DOM element i.e. a
<td>
element with Firebug<td>
element on the page and Inspect Element.<td>
...and that's all there is to it.
通常我所做的是将 jQuery 加载到 Firebug 中,将其包装为油脂猴脚本。下面是来自 http 的脚本://joanpiedra.com/jquery/greasemonkey/
Typically what I do is load jQuery inside Firebug, wrap it as a grease monkey script.Below is such a script from http://joanpiedra.com/jquery/greasemonkey/