passing variable value to href argument in anchor tag

后端 未结 6 846
[愿得一人]
[愿得一人] 2021-01-25 12:35

how to pass the variable value to href argument in anchor tag.




        
相关标签:
6条回答
  • 2021-01-25 13:02

    You're missing the # for the id. Try using $('#a_tag_id'). Use an ? before your first query string variable instead of &.

    0 讨论(0)
  • 2021-01-25 13:02

    Modify the jquery like this

     $('#a_tag_id').attr('href','http://www.google.com&jobid='+id);
    
    0 讨论(0)
  • 2021-01-25 13:06

    When your Javascript is executed, the a tag might not exist yet.

    Use:

    $(document).ready(function(){
        var id = "10";
        $('#a_tag_id').attr('href','http://www.google.com&jobid='+id);
    });
    

    Also, it should be #a_tag_id to match the id.

    0 讨论(0)
  • 2021-01-25 13:08
    $('#a_tag_id').attr('href','http://www.google.com?jobid='+id);
    

    The selector should be for id '#', and the querystring starts with "?".

    BTW: Isn't this question following up on your last question: Pass an id to anchor tag ?

    0 讨论(0)
  • 2021-01-25 13:10

    Use # for id selctor

    $('#a_tag_id').attr('href','http://www.google.com&jobid='+id);
       ^
    

    Fiddle Demo

    0 讨论(0)
  • 2021-01-25 13:12

    You have miss # in jQuery selector, and insert the code inside the document.ready to make that your script work when the page is ready

    Try this:

    <script>
    $(document).ready(function(){
       var id = "10";
       $('#a_tag_id').attr('href','http://www.google.com&jobid='+id);
    });
    </script>
    

    DEMO

    0 讨论(0)
提交回复
热议问题