Passing data to a jQuery click() function

后端 未结 5 2058
独厮守ぢ
独厮守ぢ 2021-01-01 21:21

I have a simple span like so

Remove

This span is within a table, each row has a remo

5条回答
  •  粉色の甜心
    2021-01-01 22:21

    You could try jQuery.data(): http://api.jquery.com/jQuery.data , but that would mean server-side generated js code to execute when the page loads so that you can store the ids for later reuse (your remove action)

    // this part would have to be server 'generated'
    // and by that I'm referring  to the ''
    $('table .remove').each(function(){
    
       var MyElem = $(this);
       MyElem.data('id',  );
    
       MyElem.click(function(){
          the_id = $(this).data('id');
          // ajax call goes here
       });
    
    });
    

提交回复
热议问题