jQuery - 将类从一个元素复制到另一个 IF 条件是正确的
我之后的基本想法..
在文档中,将类从“#box-one”复制到“#box-三”if“#box-two img”与“#”具有相同的图像名称box-one img”
,如果可能的话......可以从传输
html 中排除特定类:
<span id="box-one" class="first second third">
<img src="imagefolder/image1.jpg" alt />
</span>
<span id="box-two">
<img src="imagefolder2/image1.jpg" alt />
</span>
<span id="box-three"></span>
请记住,“#box-one”和“#box-two”内的图像会发生变化,但始终相同。
就js而言,我不知道如何做到这一点。这怎么能做到呢?
Basic idea of what im after..
On document ready copy classes from "#box-one" into "#box-three" if "#box-two img" has the same image name as "#box-one img"
and if possible.. with the possibility of excluding specific classes from transferring
html:
<span id="box-one" class="first second third">
<img src="imagefolder/image1.jpg" alt />
</span>
<span id="box-two">
<img src="imagefolder2/image1.jpg" alt />
</span>
<span id="box-three"></span>
Keeping in mind that the images inside "#box-one" and "#box-two" change but are always identical.
I have no idea how to do this as far as the js goes.. How could this be done?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
工作示例: http://jsfiddle.net/raPBy/
Working example: http://jsfiddle.net/raPBy/
这将添加从框一到框三的所有类,并清除框一的类。如果要移动特定类,可以使用 jQuery 方法
$.addClass
和$.removeClass
。编辑
您可以使用以下方法仅比较文件名段:
This will add all of the classes from box one to box three, and clear the class of box one. If you want to move specific classes, you can use the jQuery methods
$.addClass
and$.removeClass
.Edit
You can compare just the filename segment using:
试试这个:
Try this: