使用jQuery从rel属性获取属性 [英] Get attributes from the rel attribute with jQuery

查看:489
本文介绍了使用jQuery从rel属性获取属性的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

 < ul id =product-拇指列表> 
< li>< a href =1-big.jpg =useZoom:'cdonZoom',smallImage:'1.jpg'>< / li>
< li>< a href =2-big.jpg =useZoom:'cdonZoom',smallImage:'2.jpg'>< / li>
< / ul>

是否可以通过jQuery获取smallImage-value?

在此例如,1.jpg或'2.jpg'。



谢谢! 解决方案

以下是一种方法:

  $(#product-thumbs-list a)。each function(index){
var arrTemp = $(this).attr(rel)。split(smallImage:);
var value = arrTemp [1];
alert(值);
});

现场测试案例


Im using a plugin that requires the rel-element to look like this.

<ul id="product-thumbs-list">
      <li><a href="1-big.jpg" rel="useZoom: 'cdonZoom', smallImage: '1.jpg'"></li>
      <li><a href="2-big.jpg" rel="useZoom: 'cdonZoom', smallImage: '2.jpg'"></li>
</ul>

Is it possible to get the smallImage-value via jQuery?
In this case, '1.jpg, or '2.jpg'.

Thanks!

解决方案

Here is one way:

$("#product-thumbs-list a").each(function(index) {
   var arrTemp = $(this).attr("rel").split("smallImage: ");
   var value = arrTemp[1];
   alert(value);
});

Live test case.

这篇关于使用jQuery从rel属性获取属性的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆