使用选择
我必须做的功能就像this上的链接的点击,它会显示样箱 这是用一个大的jQuery代码在弹出的产品细节我不明白使用选择
这里是我的jsfiddle 我想给一些链接相同的类与不同的#标签来显示div ,我希望当我点击链接它解决同样的href值并显示相应的结果,但它没有工作 可以有人建议正确的方法 这里是我的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锚点击fiddle
完整的代码,我想this functionality
你应该叫$(this)
,不$('this')
-
$(this)
包装PS由this
提到一个jQuery对象中的对象, -
$('this')
会遍历所有的文件寻找HTML节点的标记this
(很像$('div')
会寻找HTML标记节点div
);由于没有,它会选择一个空的节点列表。
工作小提琴:http://jsfiddle.net/Hg4zp/3/
(有也是一个错字,调用的.hide()
.hide(")
代替)
或关闭报价,这也工作得很好(对于我在Chrome中)。 – 11684 2013-03-13 08:26:27
感谢它的工作 和.hide()是一个错误,我也想尝试一些感谢 – 2013-03-13 09:35:46
试试这个方法:
$(".show").click(function (e) { //<-----pass the event here
e.preventDefault(); //<--------------stop the default behavior of the link
var link = $(this).attr('href'); //<-remove the quotes $(this)
$(link).show();
});
$(".close").click(function() {
$(this).closest("div.popupbox").hide(); //<----use .hide(); not .hide(");
});
你应该使用在这些情况下preventDefault()
到停止点击链接时发生的跳转。
您试图显示一个链接的href对象,这是行不通的。你喜欢什么显示 – 2013-03-13 08:23:12