Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/436.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 通过单击相应行上的按钮获取特定表行值_Javascript_Jquery_Html - Fatal编程技术网

Javascript 通过单击相应行上的按钮获取特定表行值

Javascript 通过单击相应行上的按钮获取特定表行值,javascript,jquery,html,Javascript,Jquery,Html,单击“查看详细信息”按钮时,我使用Jquery获取表值,但我无法在web中检索它。 如何在单击按钮时有效地获取表格详细信息 我的代码是 Check In Check Out Duration 6/7/2013 3:24:40 PM 6/7/2013 3:26:21 PM 00:01:41:000 View button 6/7/2013 3:32:25 PM 6/7/2013 3:34:26 PM 00:02:01:000 View

单击“查看详细信息”按钮时,我使用Jquery获取表值,但我无法在web中检索它。 如何在单击按钮时有效地获取表格详细信息

我的代码是

Check In Check Out Duration 6/7/2013 3:24:40 PM 6/7/2013 3:26:21 PM 00:01:41:000 View button 6/7/2013 3:32:25 PM 6/7/2013 3:34:26 PM 00:02:01:000 View button 请查收


如果您使用JSFIDLE解释您的问题,您可以使用它获取行的索引

,这将有助于快速解决问题;它返回该行的所有html
for (var post in result) 
{   
    $("#tablegrid > tbody").append("<tr id=subtablegrid><td>"+result[post].CheckedIn+"</td><td>"+result[post].CheckedOut+"</td><td>"+result[post].Duration+"</td><td class='mapview'><a id="+viewbtnid+','+fieldstaffid+" href='#' data-role='button' >View Details</a></td></tr>");
    viewbtnid++;
}

$(document).on('click','.mapview a',function(){

    var id=$(this).attr('id');
    var idArr=new Array();
    idArr=id.split(",");
    alert(idArr[0]+" "+idArr[1]);
    var fieldstaffid=idArr[1];

    var fromDate=$("#tablegrid tbody tr:nth-child("+idArr[0]+") td:nth-child(1)").text();
    var toDate=$("#tablegrid tbody tr:nth-child("+idArr[0]+") td:nth-child(2)").text();
    fromDateTime=fromDate.substring(0,13);
    toDateTime=toDate.substring(0,13);
    alert(" to date "+toDateTime);
    alert(fromDateTime+" "+toDateTime);

});
$(document).ready(function(){
  $('table tr').click(function(){
     alert($(this).index() + 1 );
  });
});