获取"id"并在每个div中添加(名称="id") [英] Get "id" and add in each div (name = "id")

查看:156
本文介绍了获取"id"并在每个div中添加(名称="id")的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

$(document).ready(function() {
    var idPost = $('.post-outer').attr('id');
    $('.post-outer').attr('name', idPost);
});

当您运行上面的JS时,它只需要在其他"DIV"中重复第一个"ID". 发生了什么事:

When you run the JS above it only takes the first "ID" repeating in other "DIV". What is going on:

<div class="post-outer" id="001" name="001">teste1</div>
<div class="post-outer" id="002" name="001">teste2</div>
<div class="post-outer" id="003" name="001">teste3</div>

我想发生这种情况:

<div class="post-outer" id="001" name="001">teste1</div>
<div class="post-outer" id="002" name="002">teste2</div>
<div class="post-outer" id="003" name="003">teste3</div>

推荐答案

演示

$('.post-outer .post-footer .post-footer-line.post-footer-line-2 .post-labels a').each(function(index, el) {
     $(this).parents('.post-outer:eq(0)').attr('itemtype', $(this).attr('href') );
});

这篇关于获取"id"并在每个div中添加(名称="id")的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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