这就是我想要做的事情。
<div class="submenu"><a href="#a">Home</a></div>
<div class="submenu"><a href="#b">Contact</a></div>
对于Jquery,我使用attr来获取a的href链接,然后提取它的名称href,如果我理解它是#a和#b,然后我用fadeOut分配它。 / p>
$(".submenu").click(function(){
var x=$(this).children("a").attr('href');
alert(x);
$('x').fadeOut();
但它根本不起作用?有什么建议吗?
答案 0 :(得分:0)
我知道您想要点击链接的目标时执行某些操作,这是您应该做的:
//Attach the click handler to the link itself
$('.submenu a').click(function () {
//Create a new jquery object using the link's href as the selector. eg: #a
var $target = $($(this).attr('href'));
//Do whatever you want to do with the element
$target.fadeOut();
});