jquery – $(a,this).attr(‘href’)返回undefined

我使用ajax从 mysql数据库加载一些数据…我的问题是,它获取我想加载的数据的id,我已将HREF值设置为id …所以一个例子是:

`<a href="16" title="View Story: ssasds">ssasds</a>`,

16是我需要的id值…我的代码是:

$('.artefact').click(function()
                {

                var storyId = $('a',this).attr('href');
                console.log(storyId);
                               }

当我检查控制台(firebug)它只是说未定义.请尝试帮忙,因为我已经尝试过获取数据的其他方法但是变得混乱.

谢谢

解决方法

似乎.artefact有两个作为.基于此:

$('.artefact').click(function () {
    var storyId = $('a',this).filter("[href]").attr('href');
    console.log(storyId);
});

编辑

再想一想,这看起来更干净:

$('.artefact').click(function () {
    var storyId = $(this).find("a[href]").attr('href');
    console.log(storyId);
});

相关文章

页面搜索关键词突出 // 页面搜索关键词突出 $(function () {...
jQuery实时显示日期、时间 html: &lt;span id=&quot...
jQuery 添加水印 &lt;script src=&quot;../../../.....
中文:Sys.WebForms.PageRequestManagerParserErrorExceptio...
1. 用Response.Write方法 代码如下: Response.Write(&q...
Jquery实现按钮点击遮罩加载,处理完后恢复 思路: 1.点击按...