2010-02-08 55 views
1

我使用MooTools(項目的一部分)加載一個頁面使用Request.HTML,它工作正常,除了我不想整個頁面,只有一個片段有一個ID。如何使用MooTools和Request.HTML從遠程頁面獲取元素?

這是問題

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'); 

的代碼,我敢肯定,這一定是可能的,我可以搶有一個類元素。有誰知道如何做到這一點。

感謝)

回答

5

我跳上irc.freenode.net上的#mootools通道,並得到我的回答從<kamicane>自己

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'); 
3

我不熟悉Mootools的卻鑽研Request.HTML文檔時,發現這一點:

請求成功事件:的onSuccess(responseTree,responseElements,responseHTML,responseJavaScript)

responseElements - (數組)包含遠程響應的所有元素的數組。

希望這會給正確的方向來解決您的問題。

+0

是的,我想用responseTree的問題。 responseElements數組沒有多大用處: - 我的元素包含很多元素,因此找到結束標記是不可能的(這是一維數組) - 謝謝 – meouw 2010-02-08 17:39:33

+0

+1 Darmen,您正在拉右線 – meouw 2010-02-09 10:24:03

+0

很高興幫助, @meouw。感謝您的投票 – Darmen 2010-02-09 10:41:06

相關問題