我知道之前已经问过这种问题,但是一般的解决方法
$($("input").get().reverse()).each(function() { /* ... */ });
Run Code Online (Sandbox Code Playgroud)
不适合我.我有一个xml文档,其中包含我要在网页上显示的音乐会列表.所以,在JQuery中:
$.ajax({
type: "GET",
url: "concerts.xml",
dataType: "xml",
cache: false,
success: function(xml) {
$(xml).find('concert').each(function() {
/*do stuff*/
});
}
});
Run Code Online (Sandbox Code Playgroud)
但是,我想以相反的顺序显示音乐会.所以,我尝试了以下,但它不起作用:
$.ajax({
type: "GET",
url: "concerts.xml",
dataType: "xml",
cache: false,
success: function(xml) {
$($(xml).find('concert').reverse()).each(function() {
/*do stuff*/
});
}
});
Run Code Online (Sandbox Code Playgroud)
任何援助将不胜感激.谢谢.
use*_*716 17
您排除了对get()[docs]方法的调用.
// --------------------v
$($(xml).find('concert').get().reverse()).each(function() {
Run Code Online (Sandbox Code Playgroud)
这是从jQuery对象获取元素数组所必需的.这是什么让你打电话.reverse(),这是对Array.prototype.