0

问题很简单,但我不能这样做......这是我的代码:

jQuery('nav').on('click', 'a',  function(event){
    console.log(jQuery(this));
});
4

2 回答 2

1

nav必须是 class 或 Id , nav 似乎不是标准标签

如果它是一个类名

jQuery('.nav').on('click', 'a',  function(event){
    console.log(jQuery(this));
});

如果它是一个 ID

jQuery('#nav').on('click', 'a',  function(event){
    console.log(jQuery(this));
});

这里有现场演示:http: //jsfiddle.net/netme/hx8HR/

于 2013-03-28T10:31:42.597 回答
1

您的代码看起来不错....但我认为您缺少该document.ready功能

尝试这个

jQuery(function(){  //ready function
  jQuery('nav').on('click', 'a',  function(event){
    console.log(jQuery(this));
  });
});
于 2013-03-28T10:37:25.440 回答