2010-08-13 50 views
2

我有我的asp.net页面中的jQuery qtip()函数,我需要从单击的项目中获取id。有谁知道该怎么做?jQuery qtip() - 如何从被点击的项目获取id

举个例子,请看下面我的脚本代码...提前

$("#content a.toolTip").qtip({ 
  content: { url: 'PageView.aspx?Param=' + '---get id---' } 
)}; 

感谢。

[]'RPG

回答

6

如果要在设置qtip时通过this引用元素,则可以在.each()的内部执行设置。这样this引用当前元素。

$("#content a.toolTip").each(function() { 
     // Now "this" is a reference to the 
     // element getting the qtip 
     // Get the ID attribte -------------------------------v 
    $(this).qtip({ content: { url: 'PageView.aspx?Param=' + this.id } }); 
}); 
+0

多数民众赞成在正确的方式 – 2010-08-13 20:43:06

+1

它完美的工作!谢谢! – user419973 2010-08-13 20:45:46

+0

@user - 不客气。 :o) – user113716 2010-08-13 20:49:20

0

$( “#含量a.toolTip”)qtip({

内容:{URL: '?PageView.aspx帕拉姆=' + $(本).attr ('id')}

)};

+0

感谢您的快速答案,但我这样做过,它似乎并没有工作。我只有一个来自JavaScript的“未定义”字符串。 – user419973 2010-08-13 20:30:14

+0

这里'this'关键字最可能是指'document'上下文而不是实际元素。 :o) – user113716 2010-08-13 20:41:37

0

如果你需要得到一些参数,你可以欺骗这样;)

$("#content a.toolTip").each(function() 
{ 
    $(this).qtip({ 
     content: { url: 'PageView.aspx?Param=' + $(this).attr('id') } 
    }); 
});