[英]How to Get the ids of span tags
我有一组span标签,例如。
<span id="q_1" >D1</span>
<span id="q_2" >D2</span>
<span id="q_3" >D3</span>
我如何在jquery的帮助下获取span标签的ID。数字1,2,3是在运行时生成的,所以我拥有的基本结构是
<span id="q_" ></span>
$("span").each(function(){
var thisId = $(this).attr('id');
// Do whatever you want with the Id, and go on to the next one.
});
:)
$('span').each(function(){
alert($(this).attr('id'));
});
获得一个数组,如果ID:
var a = $.map($('span'), function(s){ return s.id; });
$('span');
会找到所有的跨度。
$('span').filter(function() {
return (/^q\_\d+$/i).test($(this).attr('id'));
});
或仅跨度ID匹配格式的人
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.