标题已经很明显了。
$(".js").click(function (e) {
alert('this elements href is: ' + href);
});
如何用被点击元素的href替换“href”?
$(".js").click(function (e) {
alert('this elements href is: ' + href);
});
如何用被点击元素的href替换“href”?
像这样:
$(".js").click(function (e) {
alert('this elements href is: ' + $(this).attr('href'));
}
试试这个:
alert('this elements href is: ' + this.href);//best one
或者
alert('this elements href is: ' + $(this).attr("href"));//but it is unnecessary to wrap an object into another object