如何将id附加到href

How can I append an id to href?

本文关键字:href id      更新时间:2023-09-26

我不知道什么是我的问题的正确术语,但我想把客户id到href,如href='index.php/site/get_all_services_ajax/{obj.customer[I].customer_id}.

参见我的代码中的第5行。我该怎么做呢?

<div id='mycoord'></div>
<script>
    $(document).ready(function() {
        $.get('<?php echo base_url();?>index.php/site/get_all_customer_ajax', function (data) {
            var obj = JSON.parse(data)
            for (var i=0; i < obj.customer.length; i++)
            {
                $('#mycoord').append("<a href='<?php echo base_url();?>index.php/site/get_customer_info/{obj.customer[i].customer_id}' <h2>" + obj.customer[i].first_name + "</href></h2><br>");
            }
        })
     });
</script>

应该可以了-

 $(document).ready(function() { 
        $.get('<?php echo base_url();?>index.php/site/get_all_customer_ajax', function (data) {
            var obj = JSON.parse(data)
            for (var i=0;i <obj.customer.length;i++)
            {
            $('#mycoord').append("<a href='<?php echo base_url();?>index.php/site/get_customer_info/{"+obj.customer[i].customer_id+"}' <h2>" + obj.customer[i].first_name + "</href></h2><br>");
            }
        })
     });