这个 jQuery 选择器是什么:a[@rel*=lightbox]?
我正在对一些逻辑进行一些重构,我遇到了这段代码,我仍在尝试理解它
try {
$('a[@rel*=lightbox]').lightBox();
} catch (e) {}
我理解 try catch 部分,但这部分是什么
('a[@rel*=lightbox]')
I am doing a bit of refactoring on some logic and i came across this chunk of code and i am still trying to understand it
try {
$('a[@rel*=lightbox]').lightBox();
} catch (e) {}
I understand the try catch part but what is this part
('a[@rel*=lightbox]')
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
这是旧的 XPath 方式,表示在其
rel
属性中查找带有lightbox
的锚点。因此它会匹配像下面的示例这样的锚点...它已被弃用并从新版本的 jQuery 中删除。要使其适用于最新版本,只需删除
@
:It is the old XPath way of saying find anchors with
lightbox
in theirrel
attribute. So it would match an anchor like the example below...It has been deprecated and removed from new versions of jQuery. To get it to work with the latest versions, just drop the
@
:这是一个使用已弃用的
@
(XPath ) 语法。This is an Atrribute Contains selector using deprecated
@
(XPath) syntax.有一种更好的方法来编写这个选择器。
这将选择具有“lightbox”关系的任何图像标签。您不需要执行 try 语句,如果您已正确包含所有脚本,它应该可以正常工作。
There is a better way to write this selector.
This will select any image tags with the relationship of "lightbox". You shouldn't need to do a try statement, if you've correctly included all your scripts it should work fine.
它选择属性 rel 中包含 lightbox 的所有链接
It selects all links that contains lightbox in the attribute rel
它正在页面上寻找包含启动灯箱窗口的链接的链接。
It's looking for links on the page that have somelink to launch a lightbox window.