jQuery获取页面上的所有ID [英] jQuery get all ids on page
本文介绍了jQuery获取页面上的所有ID的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
是否可以使用jQuery获取包含所有ID的数组?
Is it possible to get an array consisting of all id's on a page with jQuery?
推荐答案
您可以执行以下操作:
var ids = new Array();
$('[id]').each(function() { //Get elements that have an id=
ids.push($(this).attr("id")); //add id to array
});
//do something with ids array
我看到一个测试过的笔记,如果启用了FireBug控制台,请注意.
One note I saw testing this, the FireBug console counts as one, if that's enabled just be aware.
这篇关于jQuery获取页面上的所有ID的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文