How to use JavaScript variable in an HTML link

后端 未结 4 1800
面向向阳花
面向向阳花 2021-01-27 22:18

The website that I am working on has a tag point to a different URL than the one that the website has. What I would like to do is get around the

4条回答
  •  暖寄归人
    2021-01-27 22:42

    I would have done it this way

    HTML

    1. Link1
    2. Link2
    3. Link2

    Javascript/Jquery

    $(function(){
        var trueURL = window.location.href;
        var i = 1;
        $('a.build').each(function(){
            $(this).attr('href', trueURL + '#link' + i);
            i = i+1;
        });
    });
    

    Example of working code Here

提交回复
热议问题