jQuery返回b.fn.b.init [102] [英] Jquery returns b.fn.b.init[102]
问题描述
我必须选择多个元素,所有元素都具有"org-box"类.在该框内,有一个我要捕获href的链接.所以我这样做
I have to select multiple elements, all them have the class ="org-box". Inside that box there is a link a that I want to capture the href. So I do this
$("a.org-box").click(function (e) {
e.preventDefault();
var link = $(e).html();
$('.col-right').prepend("<b>" + link +"</b>");
})
我总是得到的是null,并且我尝试了其他选择器,例如
var link = $(e.a).attr("href").html();
What I always get is null, and I have tried other selectors like
var link = $(e.a).attr("href").html();
同样幸运.
我检查了从选择$("a.org-box")
中得到的结果,然后得到了-> b.fn.b.init [102]
I checked what I get from that selection $("a.org-box")
and I get this -> b.fn.b.init[102]
如果执行此操作$("a.org-box:first").attr("href");
,我将正确获得href,但是当执行$("a.org-box").attr("href");
时,我将获得第一个.
If I do this $("a.org-box:first").attr("href");
I get correctly the href, but when I do $("a.org-box").attr("href");
I just get the first one.
我在做什么不好?如何选择所有a.org-box并在单击时捕获href?
What Im doing bad ?? How to select all the a.org-box and capture href on click ?
推荐答案
<a href="http://google.com" class="org-box">Click to prepend Google</a>
-
$("a.org-box").on('click', function(e) {
e.preventDefault();
$('.col-right').prepend("<b>" + e.target.href +"</b>"); //http://google.com
});
这篇关于jQuery返回b.fn.b.init [102]的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!