当进入dom时匹配img src的一部分并将一个类添加到
;匹配的标签 - jquery
我有一个 ajax 加载的图像库,它将图像加载到 dom,然后将其删除并加载到下一个图像中并以这种方式旋转。
在图像进入的位置旁边,我有一个图像的静态名称列表(它们在页面加载时存在,并且不执行任何操作)。
我想要做的是,当图像加载到 dom 中时,我想将其 src 属性的一部分与类/ id / rel / 列表中的任何名称相匹配。
期望的结果是,当图像显示时,它的名称会带有下划线,然后当它显示时,它的名称不再带有下划线,因为下一个图像名称现在已带有下划线......
我真的遇到了麻烦,如果有人可以显示我该怎么做我真的非常感激!
谢谢你!
I've got an ajax loaded image gallery that loads an image to the dom and then removes it and loads in the next one and rotates in that way.
Next to where the image comes in i've got a list of static names (they're there on page load and don't do anything) for the images.
What i want to do is as the image is loaded into the dom, i want to match part of it's src attribute to the class / id / rel / whatever of the name in the list.
The desired result is that as the image displays, it's name gets underlined and then when it goes it's name is not underlined anymore as the next images name has now become underlined...
I'm having real trouble with this, if anyone can show me how to do this i would be really bloody grateful!
Thank you!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您可以使用 jQuery 的
.load()
方法(更准确地说,图像的load 事件
,例如您也可以在
window 对象
。当所有图像(作为副作用,它也会等待一些其他的东西,如iframes
)被加载时,它就会被触发。
you can use jQuerys
.load()
method (more precisly, theload event
for images likeyou may also call
.load()
on thewindow object
. That is fired when all images (as a side effect it waits for some other things likeiframes
too) are loaded.And do your checking right there.
没有所有复杂的正则表达式,您可以按照最初建议的方式使用 id/rel 属性。使用此方法,您将不会匹配图像 src 标签,而是匹配它的 ID 属性。
这是您的描述
这是您的下划线的 CSS 类
的 ajax'ed 示例格式
这是加载图像时
,您可以使用 jquery 进行匹配现在可以执行以下操作现在带有 id item_image_6 的图像将与 p 标记匹配item_desc_6
对我来说给你确切的答案有点困难,因为我看不到你在内容中使用ajax的代码。
Without all complex Regex in the way you can use id/rel attributes as you suggested initially. With this method you would not be matching the images src tag but matching it's ID attribute.
Here are your descriptions
Here is your CSS class for the underline
Here is an example forat of the ajax'ed in
When loading in your image and you can match that with jquery you can do
Now an image with id item_image_6 would match the p tag with item_desc_6
It was a little difficult for me to give you the exact answer because i couldn't see your code that was ajaxing in the content.
编辑 - 我会做这样的事情
/some regex/ 应该返回你想要匹配的部分
EDITED - I'd do something like this
the /some regex/ should return the part you want to match