如何使用javascript点击1st td复选框获得2nd td的值?

时间:2017-06-30 13:03:50

标签: javascript php jquery html

点击中的时,我想要 out 值。您可以轻松地在下面的图像中显示

enter image description here

使用数组打印时间表下方。所有数据都在数组中,我必须以表格格式打印

这是我的HTML代码:

      <table class="table nonStriped" width="100%">
<?php
$type = array();
foreach ($report as $key => $r) {
    echo "
                    <thead>
                        <tr style='border-bottom:1px solid #DDDDDD;'>
                            <th>{$empName[$key]['name_title']} {$empName[$key]['name_first']} {$empName[$key]['name_last']}</th>
                            <th colspan=\"2\" width=\"20%\"></th>
                            <th colspan=\"2\" width=\"20%\"></th>
                        </tr>
                        <tr>
                            <th width=\"10%\" class=\"table-right-left\">Date</th>
                            <th width=\"5%\" class=\"table-right-left\">AM/PM (60m/hr)</th>
                            <th width=\"5%\" class=\"table-right-left\"></th>
                            <th width=\"15%\" class=\"table-right-left\"></th>
                            <th width=\"15%\" class=\"table-right-left\">Hours Worked (hr/100)</th>
                        </tr>
                    </thead>
                    ";
    foreach ($r as $dataKey => $data) {
        $day = date('l', strtotime($dataKey)) . ', ' . date('m/d/Y', strtotime($dataKey));
        $value = "record" . $key . strtotime($dataKey);
        foreach ($data as $reKey => $d) {
            if ($reKey == 'count') {
                echo "
                                <tr>
                                     <td colspan=\"4\"><input type='checkbox' name='timeAll' onchange=checkAll('$value',this);>&nbsp;$day</td>
                                     <td style='text-align: center;'>$d</td>
                                </tr>";
            }
        }
        foreach ($data as $reKey => $d) {
            if ($reKey != 'count') {
                if ($d['approved'] == 0 && ($d['record_type'] == "in" || $d['record_type'] == "observation")) {
                    if (!in_array($d['record_type'], $type)) {
                        array_push($type, $d['record_type']);
                        $check = "<input type='checkbox' name='timeLog$key' class='$value' value='{$d['id']}'>&nbsp;&nbsp;";
                    } else {
                        $check = "&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    }
                } else if ($d['record_type'] == "out" && $d['approved'] == 0 && (in_array("in", $type) || in_array("observation", $type))) {
                    $check = "<input type='hidden' name='out_hidden' class='out_hidden' value='{$d['id']}'/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    array_pop($type);
                } else if ($d['approved'] == 1 && ($d['record_type'] == "in" || $d['record_type'] == "observation")) {
                    $check = "<a onclick=unApprove({$d['id']});>(unapprove)&nbsp;&nbsp;</a>";
                } else if ($d['record_type'] == "out" && $d['approved'] == 1) {
                    $check = "<input type='hidden' name='out_approve' class='out_approve' value='{$d['id']}'/>&nbsp;&nbsp;&nbsp;&nbsp;&nbsp;";
                    array_pop($type);
                }

                echo "
                                <tr>
                                    <td>&nbsp;&nbsp;&nbsp;$check<a title='Edit' href='/timeclock/edittimeclock/{$d['id']}' style='color: #{$d['color']}'>{$d['record_type']}</a></td>
                                    <td width=\"10%\" class=\"table-right-left\">{$d['time']}</td>
                                    <td width=\"5%\" class=\"table-right-left\" style='color: #{$d['color']}'>{$d['ipaddress']}</td>
                                    <td width=\"15%\" class=\"table-right-left\">{$d['note']}</td>
                                    <td width=\"10%\" class=\"table-right-left\"></td>
                                </tr>
                                ";
            }
        }
    }
    $total = array_sum($hours[$key]);
    echo "
                        <tr>
                            <td><b>Total Hours</b></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td style='text-align: center;'>$total</td>
                        </tr>
                        <tr>
                            <td><input type='button' name='approve' id='approve' value='APPROVE HOURS SELECTED' onclick=approve('$key');></td>
                            <td></td>
                            <td></td>
                            <td></td>
                            <td></td>
                        </tr>";
}
?>

我的时间表数组是:

Array 
    ( 
    [1] => Array 
        ( 
            [2017-06-29] => Array 
                ( 
                    [count] => 5.17 
                    [58] => Array 
                        ( 
                            [id] => 58 
                            [empId] => 1 
                            [date] => 06/29/2017 
                            [time] => 09:30 
                            [ipaddress] => 127.0.0.1 
                            [note] =>  
                            [record_type] => in 
                            [color] => 009900 
                            [approved] => 0 
                            [timestamp] => 2017-06-29 09:30:00 
                            [hrCount] => 0 
                        ) 

                    [68] => Array 
                        ( 
                            [id] => 68 
                            [empId] => 1 
                            [date] => 06/29/2017 
                            [time] => 10:00 
                            [ipaddress] => 127.0.0.1 
                            [note] =>  
                            [record_type] => in 
                            [color] => 009900 
                            [approved] => 0 
                            [timestamp] => 2017-06-29 10:00:00 
                            [hrCount] => 0 
                        ) 

                    [59] => Array 
                        ( 
                            [id] => 59 
                            [empId] => 1 
                            [date] => 06/29/2017 
                            [time] => 11:30 
                            [ipaddress] => 127.0.0.1 
                            [note] =>  
                            [record_type] => out 
                            [color] => FF9900 
                            [approved] => 0 
                            [timestamp] => 2017-06-29 11:30:00 
                            [hrCount] => 2.0 
                        ) 

                    [62] => Array 
                        ( 
                            [id] => 62 
                            [empId] => 1 
                            [date] => 06/29/2017 
                            [time] => 11:45 
                            [ipaddress] => 127.0.0.1 
                            [note] =>  
                            [record_type] => in 
                            [color] => 009900 
                            [approved] => 0 
                            [timestamp] => 2017-06-29 11:45:00 
                            [hrCount] => 0 
                        ) 

                    [63] => Array 
                        ( 
                            [id] => 63 
                            [empId] => 1 
                            [date] => 06/29/2017 
                            [time] => 13:15 
                            [ipaddress] => 127.0.0.1 
                            [note] =>  
                            [record_type] => out 
                            [color] => 0000FF 
                            [approved] => 0 
                            [timestamp] => 2017-06-29 13:15:00 
                            [hrCount] => 1.50 
                        ) 

                    [67] => Array 
                        ( 
                            [id] => 67 
                            [empId] => 1 
                            [date] => 06/29/2017 
                            [time] => 14:20 
                            [ipaddress] => 127.0.0.1 
                            [note] =>  
                            [record_type] => in 
                            [color] => 009900 
                            [approved] => 0 
                            [timestamp] => 2017-06-29 14:20:00 
                            [hrCount] => 0 
                        ) 

                    [69] => Array 
                        ( 
                            [id] => 69 
                            [empId] => 1 
                            [date] => 06/29/2017 
                            [time] => 16:00 
                            [ipaddress] => 127.0.0.1 
                            [note] =>  
                            [record_type] => out 
                            [color] => FF9900 
                            [approved] => 0 
                            [timestamp] => 2017-06-29 16:00:00 
                            [hrCount] => 1.67 
                        ) 

                ) 

            [2017-06-30] => Array 
                ( 
                    [count] => 3.67 
                    [71] => Array 
                        ( 
                            [id] => 71 
                            [empId] => 1 
                            [date] => 06/30/2017 
                            [time] => 09:30 
                            [ipaddress] => 127.0.0.1 
                            [note] =>  
                            [record_type] => in 
                            [color] => 009900 
                            [approved] => 0 
                            [timestamp] => 2017-06-30 09:30:00 
                            [hrCount] => 0 
                        ) 

                    [72] => Array 
                        ( 
                            [id] => 72 
                            [empId] => 1 
                            [date] => 06/30/2017 
                            [time] => 11:30 
                            [ipaddress] => 127.0.0.1 
                            [note] =>  
                            [record_type] => out 
                            [color] => FF9900 
                            [approved] => 0 
                            [timestamp] => 2017-06-30 11:30:00 
                            [hrCount] => 2.0 
                        ) 

                    [73] => Array 
                        ( 
                            [id] => 73 
                            [empId] => 1 
                            [date] => 06/30/2017 
                            [time] => 11:40 
                            [ipaddress] => 127.0.0.1 
                            [note] =>  
                            [record_type] => in 
                            [color] => 009900 
                            [approved] => 0 
                            [timestamp] => 2017-06-30 11:40:00 
                            [hrCount] => 0 
                        ) 

                    [74] => Array 
                        ( 
                            [id] => 74 
                            [empId] => 1 
                            [date] => 06/30/2017 
                            [time] => 13:20 
                            [ipaddress] => 127.0.0.1 
                            [note] =>  
                            [record_type] => out 
                            [color] => 0000FF 
                            [approved] => 0 
                            [timestamp] => 2017-06-30 13:20:00 
                            [hrCount] => 1.67 
                        ) 

                    [75] => Array 
                        ( 
                            [id] => 75 
                            [empId] => 1 
                            [date] => 06/30/2017 
                            [time] => 14:20 
                            [ipaddress] => 127.0.0.1 
                            [note] =>  
                            [record_type] => in 
                            [color] => 009900 
                            [approved] => 0 
                            [timestamp] => 2017-06-30 14:20:00 
                            [hrCount] => 0 
                        ) 

                ) 

        ) 

)

任何与问题有关的问题请写在评论中。请帮我找出路。

1 个答案:

答案 0 :(得分:1)

$(document).on('click', '.table', function () {
    var value = $(this).closest('tr').find('td:eq(2)').find('out_hidden').val();
});