简体   繁体   中英

pass id to a tag href in modal(bootstrap)

hy, i want to pass my id to a tag href in my modal(bootstrap), for know i using this to past my id from my modal button:

        modal.find('#down').attr('href', function(i, href) {
            return href + div.data('id');
        });

this is my a tag:

  <a type="button" id="down" href="<?php echo base_url(); ?>/aprove/download/">Berkas</a>

this is my modal button:

<a href="javascript:;" title="Lihat" data-id="<?php echo $q->id_project ?>"  data-toggle="modal" data-target="#lihat-data">                                                        <button data-toggle="modal" data-target="#ubah-data" class="btn btn-secondary"><i class="far fa-eye"></i></i></button>                                                  </a>

the problem its, every time i click the modal button, my a tag(href) will add previous id to the new one, like this:

first modal:

href="http://localhost/pe//aprove/download/4"

second modal:

href="http://localhost/pe//aprove/download/41"

i need to refresh the table to make it just get their own id

So do something like

<a type="button" id="down" data-href="<?php echo base_url(); ?>/aprove/download/">Berkas</a>

and read the data attribute

var anchor = modal.find('#down')
anchor.attr('href', anchor.data('href') + div.data('id'));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM