在变量jquery中使用选择器 [英] use selectors in variable jquery
问题描述
点击链接后,我必须使此这样的功能在弹出框(如框)中显示产品详细信息 这使用的是我不明白的大型jQuery代码
i have to made functionality like this on click of a link it will show the product details in a popup like box this is using a big jquery code i didn't understand
这是我的 jsfiddle 我正在尝试给同一个链接使用不同的#tags来显示div 我想当我单击链接时,它解析相同的href值并显示相应的结果,但是没有用 有人可以建议正确的方法吗 这是我的JS
and here is my jsfiddle i am trying to give some links same class with different #tags to show the div and i want that when i click on link it resolves the href value of the same and show the corresponding result but it didnt works can somebody suggest the right way here is my JS
$(".show").click(function() {
var link = $('this').attr('href');
$(link).show();
});
和html
<a href="#popup" id="show" class="show">a</a>
<a href="#popup1" id="show1" class="show">b</a>
<a href="#popup2" id="show2" class="show">c</a>
我想在锚点点击时显示#popup
i want to show #popup on anchor click
小提琴上的完整代码,我想
full code on fiddle and i want this functionality
推荐答案
您应该致电$(this)
,而不是$('this')
-
$(this)
将this
引用的对象包装在jQuery对象中, -
$('this')
将遍历您的所有文档以查找标记为this
的html节点(很像$('div')
将寻找标记为div
的html节点);既然没有,它将选择一个空节点列表.
$(this)
wraps the object referred to bythis
inside a jQuery object,$('this')
will traverse all of your document looking for html nodes taggedthis
(much like$('div')
will look for html nodes taggeddiv
); since there isn't any, it will select an empty list of nodes.
工作小提琴: http://jsfiddle.net/Hg4zp/3/
(还有一个错字,叫.hide(")
而不是.hide()
)
( there also was a typo, calling .hide(")
instead of .hide()
)
这篇关于在变量jquery中使用选择器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!