jQuery Selector里面的变量? [英] jQuery Selector inside of variable?

查看:81
本文介绍了jQuery Selector里面的变量?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

您好我正在试图获得所有DIV的ID,在另一个HTML文件中,与一个特定的类。
加载我使用的文件:

  $。get(blocks.html,function(data){ 
//这里我不知道如何:)
});

现在我正在寻找的东西是这样的:

  data。$('。block')。each(...其余没有问题

,这样我就可以使用不在我的页面代码中的jQuery选择器,而是在数据变量的争用中使用
感谢您的帮助!


$ div class =h2_lin>解决方案

  $。get(blocks.html,function(data){
var ids = $('< div />')。html(data).find('div.block')。map(function(){
return this.id;
})。get );
});


Hi I'm trying to get the IDs of all DIVs, inside another HTML File, with a specific Class. To load the file I use:

$.get("blocks.html", function(data) {
        //here I don't know how :)
});

Now what I'm looking for ist something like this:

data.$('.block').each(... the rest is no problem

so that I use the jQuery selectors not on my page code but instead inside the contend of the data variable. Thanks for help!

解决方案

$.get("blocks.html", function(data) {
    var ids = $('<div/>').html(data).find('div.block').map(function() {
        return this.id;
    }).get();
});

这篇关于jQuery Selector里面的变量?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆