我正在使用 MooTools(项目的一部分)使用 Request.HTML
加载一个页面,它工作正常,除了我不想要整个页面,只有一个具有 id 的片段.
这是有问题的代码
var req = new Request.HTML({
onSuccess: function( res ) {
// according to the docs
// res should be the node list of the remote response
// I want to grab #myFragment
var f = res.getElementById('myFragment');
// res.getElementById is not a function
var f = $(res).getElementById('myFragment');
// $(res) is null ?
var f = $$(res).getElementById('myFragment');
// [null, null] ??
// more code
}
}).get('/myurl');
我很确定这一定是可能的,我可以获取具有类的元素。有谁知道如何做到这一点。
谢谢)
最佳答案
我跳上了 irc.freenode.net 上的#mootools channel ,并从
var req = new Request.HTML({
onSuccess: function( responseTree, responseElements /*more*/ ) {
// responseElements is the one I want
//it's an array of elements which you can filter
var f = responseElements.filter('#myFragment');
// do stuff with my fragment
}
}).get('/myurl');
关于javascript - 如何使用 MooTools 和 Request.HTML 从远程页面抓取元素?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/2223395/