gpt4 book ai didi

javascript - 如何获取span标签的id

转载 作者:行者123 更新时间:2023-11-28 11:07:45 25 4
gpt4 key购买 nike

我有一组 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.
});

:)

关于javascript - 如何获取span标签的id,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5593808/

25 4 0