我正在尝试使用 jQuery 获取 anchor 的 href 属性。但是,当我尝试检查放置 href 属性的变量的值时,它显示未定义。
$("#chk1").click(function(){
var button_link = $("#buttonAdd").find("href").attr('href');
//or (I tried 2 ways)
var button_link = $("#buttonAdd").attr('href');
alert(button_link);
});
如何使用 jQuery 正确捕获 anchor 的 href 属性?
编辑:
添加 anchor 链接供您引用:
<a href="Vehicle/VehicleEditor.aspx?sfId=299798&st=ON&recloc=&ID=&manualReqID=0&trID=21838518&SeqNo=1" id="buttonAdd">Add</a>
最佳答案
您需要找到 A
元素。我们可以做到这一点。
$("#buttonAdd").find("a").attr('href');
关于javascript - 使用 ID 从 anchor 获取 href 显示未定义,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/24376914/