我正在使用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频道,并从自己得到了答案。
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/