我想找到这个HTML字符串中的每个“一”标签中的每个环节找到与jQuery和HTML字符串
$(document).ready(function(data) {
$.get('test.html',
function(responseText){
//find each a tag
}, "html"
)
});
,这是为什么对我这么该死的困难?
我想找到这个HTML字符串中的每个“一”标签中的每个环节找到与jQuery和HTML字符串
$(document).ready(function(data) {
$.get('test.html',
function(responseText){
//find each a tag
}, "html"
)
});
,这是为什么对我这么该死的困难?
越来越各个环节,做一些与他们:
$.get('test.html', function(responseText) {
var $response = $(responseText);
var $links = $response.find('a');
$links.each(function(index, $link) {
// go nuts
});
});
的详情,请阅读jQuery的文档 - 它很不错!
创建HTML的jQuery对象和使用.find()
:
$(responseText).find('a');
试试这个:
$(responseText).find('a')
我不知道任何代码是否工作,如果responseText
是一个字符串。
您必须首先登录HtmlEncode it using jQuery,然后找到您的anchor
标记。
例子:
$("<div/>").html(responseText).find('a').each(function(idx, elm) {
//here are your anchors
//alert(elm.href);
});
工作演示:http://jsfiddle.net/naveen/Tcp3t/
希望这有助于。
看来你得到了正确的答案。但是,如果没有任何参考标签,您可能会遇到明文形式的链接,以便像我那样查找它。
我发现这个jQuery插件,可以indetify文本中的链接,然后创建标签
希望这将帮助别人
很酷,但我怎么把链接变量?例如,var $ links = $ response.find('a'); – danielovich
更新了我的答案。 – jrharshath