【问题标题】:need to get rel attribute and href attribute when making a while div clickable in jquery在jquery中制作while div可点击时需要获取rel属性和href属性
【发布时间】:2010-01-18 14:34:23
【问题描述】:

嘿,在 jQuery 中传递参数值时遇到一些问题。我需要一个 div 来打开一个作为 Shadowbox 对话框打开的链接。(Shadowbox 使用 rel 标签)因此我需要获取 href 和 rel 的值,但无法弄清楚。我试图将 .attr("rel") 添加到字符串中,但没有用。

我的 jquery:

$("div.banner").click(function() {  
     window.location = $(this).find("a").attr("href"); return false;     }); 

谢谢!

【问题讨论】:

    标签: jquery jquery-selectors


    【解决方案1】:

    我不完全确定你在追求什么,但如果你想在构建 window.location 字符串时同时使用 rel 和 href 属性,你需要做这样的事情。

    $("div.banner").click(function() {
        var $link = $(this).find("a");
        window.location = $link.attr("href") + $link.attr("rel");
        return false;
    });
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2011-10-01
      • 2020-02-07
      • 1970-01-01
      • 2012-01-28
      • 2016-06-07
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多