本文介绍了如何使用MooTools和Request.HTML从远程页面获取元素?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用MooTools(项目的一部分)使用 Request.HTML
加载页面,除非我不想要整个页面,一个有id的片段。
I'm using MooTools ( part of the project ) to load a page using Request.HTML
which works fine except that I don't want the whole page, just one fragment which has an 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');
我很确定这一定是可行的,我可以抓住有类的元素。有谁知道怎么做。
I'm pretty sure this must be possible, I can grab elements that have a class. Does anyone know how to do this.
谢谢)
推荐答案
我跳到了irc.freenode.net上的#mootools频道,并从< kamicane>获得了答案。他自己
I hopped onto the #mootools channel on irc.freenode.net and got my answer from <kamicane> himself
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');
这篇关于如何使用MooTools和Request.HTML从远程页面获取元素?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!