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

后端 未结 5 770
北荒
北荒 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:11

    check http://jsfiddle.net/Z22NU/12/

    function fnselect(){
    
        alert($("tr.selected td:first" ).html());
    }
    
    0 讨论(0)
  • 2020-12-02 19:16

    You can access the first element adding the following code to the highlight function

    $(this).find(".selected td:first").html()

    Working Code:JSFIDDLE

    0 讨论(0)
  • 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());
        });
    });
    
    0 讨论(0)
  • 2020-12-02 19:26

    This below code will give selected row, you can parse the values from it and send to the AJAX call.

    $(".selected").click(function () {
    var row = $(this).parent().parent().parent().html();            
    });
    
    0 讨论(0)
  • 2020-12-02 19:34
    $("#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());
    });
    

    Demo:

    http://jsfiddle.net/65JPw/2/

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