使用jQuery从另一个页面获取hrefs
Get hrefs from another page with jQuery
我正试图创建一个函数,该函数从另一个页面获取链接列表,并将它们推送到一个数组中,但在成功函数之后,我一直在做什么。
$('#button').click(function() {
var array = [];
$.get('links.html',function(data) {
//here's where I'm stuck
$('#photo a').each(function(){
array.push($(this).attr('href'));
});
});
links.html
<html>
<body>
<div id="photo">
<a href="link1.html">...
<a href="link2.html">...
谢谢
试试这个。
$('#button').click(function() {
var array = [];
$.get('links.html',function(data) {
//here's where I'm stuck
$(data).find('#photo a').each(function(){
array.push($(this).attr('href'));
});
});
});
$(data).find('#photo a')
您需要在ajax调用返回的数据中搜索链接。
相关文章:
- 使用 jQuery 的 .on 函数如何获取事件的原始元素
- jquery试图按名称获取按钮位置
- 如何在jQuery中获取元素的形式
- 如何在php文件中获取$.post-ajax传递的值
- 在Shopify中获取博客文章的图片
- 使用Javascript获取所选选项ID
- 在jQuery中获取表的行索引
- 使用jquery将mysql数据获取到新的表行中
- 在动态创建的元素上获取对特定选择器的引用
- 从城市名称获取惊喜
- Angular只从数组中获取所需的数据
- 无法将数据从firebase获取到我的html页面
- 从ajax请求中获取javascript对象
- 如何从画布上的某个移动事件中获取X和Y
- 是否有一个JS/jQuery函数可以获取某个类的每个元素的ID
- 如何在PHP中使用$_POST获取Select元素值
- 获取@ResponseBody的一部分作为主干和Spring MVC控制器之间的参数
- 从Rally获取一个特定的标记,以便计算另一个字段中的值
- Twitter Bootstrap typeahead:使用“this”获取上下文/调用元素
- 使用jQuery从另一个页面获取hrefs