这是一个超级简单的问题,我似乎无法找到一个好的答案了。jQuery GET html作为遍历jQuery对象
$.get('/myurl.html', function(response){
console.log(response); //works!
console.log($(response).find('#element').text()); //null :(
}, 'html');
我只是想遍历我的html响应。到目前为止,我能想到的唯一办法就是将正则表达式内置到body标签中,并将其用作字符串来创建我的遍历jQuery对象。但那似乎很愚蠢。任何人都在意指出正确的方式来做到这一点?
也许是我的html?
<html>
<head>
<title>Center</title>
</head>
<body>
<!-- tons-o-stuff -->
</body>
</html>
这也工作正常,但并不适合我的需求:
$( '#myelem')负载( '/ myurl.html #element');
如果您在响应html中寻找具有值为“element”的“id”属性的某个元素,那么它对我来说看起来是正确的。我不知道为什么这不起作用。 – jessegavin 2012-04-05 16:44:07
你提取的html是怎么样的? – 2012-04-05 16:44:15
这应该回答你的问题: http://stackoverflow.com/questions/9540218/a-javascript-parser-for-dom/9540313#9540313 – 2012-04-05 16:46:07