Select a row from html table and send values onclick of a button

后端 未结 5 791
北荒
北荒 2020-12-02 18:41

I have HTML table where I need to select a row and send its first cell ID to a button and onclick of the button send the selected value to a function in Javascr

5条回答
  •  一个人的身影
    2020-12-02 19:17

    In my case $(document).ready(function() was missing. Try this.

    $(document).ready(function(){   
    ("#table tr").click(function(){
           $(this).addClass('selected').siblings().removeClass('selected');    
           var value=$(this).find('td:first').html();
           alert(value);    
        });
        $('.ok').on('click', function(e){
            alert($("#table tr.selected td:first").html());
        });
    });
    

提交回复
热议问题