简体   繁体   English

使用jquery获取href形式的链接

[英]Get the link form a href using jquery

Using jQuery how could I obtain the link inside this a tag? 使用jQuery我怎么能获得这里面链接a标签?

<a title="Rainham Pizza and Kebab" href="/rainham-pizza" class="restsRestStatus restPageLink  restsStatusOpens"><b>Pre-order</b><span>Opens         16:00       </span></a>

I have tried using: 我试过使用:

jQuery("a.restsRestStatusrestPageLinkrestsStatusOpens").html();
$("a.restsRestStatus.restPageLink.restsStatusOpens").attr("href");

Try using .attr() as shown :- 尝试使用.attr() ,如下所示:

var url = $('a.restsRestStatus').attr('href');
alert(url);

OR 要么

var url = $("a.restsRestStatus.restPageLink.restsStatusOpens").attr("href");
alert(url);

您可以在jquery中使用.attr()

("a.restsRestStatus.restPageLink.restsStatusOpens").attr("href")
var link = $('a.restPageLink').attr('href');
href = $('a').attr("href");
alert(href);

尝试这个...

var link =$(element).attr("href");

use prop() over attr() in the majority of cases. 在大多数情况下,在attr()上使用prop()。

prop() is the current state of the input element, attr() is the default value. prop()是输入元素的当前状态,attr()是默认值。

prop() can contain things of different types, attr() can only contain strings prop()可以包含不同类型的东西,attr()仅可以包含字符串

var url = $('a.restsRestStatus ').prop('href');

你需要

var href = $(this).attr('href');

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM