开发者

Iterate Through Dynamic tags and populate using jquery

开发者 https://www.devze.com 2023-02-10 02:43 出处:网络
I have this so far... <script type=\"text/javascript\"> $(document).ready(function () { $(\'ul\').addClass(\'navMenu\');

I have this so far...

<script type="text/javascript">
    $(document).ready(function () {
        $('ul').addClass('navMenu');
        $('li').addClass('todo').html("<span class='navItemHead'></span>");
        $('span.navItemHead').wrap("<a href='/My/Website'></a>");
    });
</script>

I have four names I want to put into the name tag Mary,Nick,Matt,Meg and 1,2,3,4 in the span tag, so the final html should read.....

 <li class="todo ">
        <a href="/Register/Website"><span class="navItemHead">1</span>Mary</a>       
 </li>
 <li class="todo ">
        <a href="/Register/Website"><span class="navItemHead">2</span>Nick开发者_如何学运维</a>
 </li> ....etc


var names = ['Mary', ...];
$('li').addClass('todo').html(function (i) {
    return "<a href='/My/Website'><span class='navItemHead'>" + (i + 1) + "</span>" + names[i] + "</a>";
});
0

精彩评论

暂无评论...
验证码 换一张
取 消