Jquery在按钮上单击

时间:2018-04-25 10:55:47

标签: jquery button html-table click

我有一个通过PHP / mysql生成的表。在每行的末尾是按钮。根据单击的按钮,我希望相关的隐藏行仅显示在单击按钮的行上。

HTML来源

<?php
if ($result = mysqli_query($link, $query)) {
    while ($row = mysqli_fetch_array($result)) {
    echo    
        '<tbody>
            <tr class="parent"> 
                <td align="left">'. $row['reference'] . '</td>
                <td align="left">'. $row['animal'] . '</td>
                <td><input type="button" name="ownorwant" value="own"></td>
                <td><input type="button" name="ownorwant" value="want"></td>
            </tr>'; 
    echo    '<tr style="display: none;" class="child1"> 
                <td><input type="button" name="size" value="big" /></td>
                <td><input type="button" name="size" value="small" /></td>
            </tr>';
    echo    '<tr style="display: none;" class="child2">   
                <td><input type="button" name="food" value="meat" /></td>
                <td><input type="button" name="food" value="veg" /></td>
            </tr>';    
    echo    '<tr style="display: none;" class="child3"> 
                <td><input type="submit" name="save" value="save" /></td>
            </tr>
        </tbody>';
?>

Jquery代码

$('.ownorwant').on('click', function(){
    var val =$(this).val();
    if (val === "own"){
        $( this ).find('.child1').show();}
    else{
        $( this ).find('.child3').show();}
    });
});

1 个答案:

答案 0 :(得分:0)

试试这个

&#13;
&#13;
Sub vbax_53997_Compare_Two_Ranges()
    Dim i As Long
    Dim wb1ws1, wb2ws2
    Dim blnSame As Boolean

    wb1ws1 = Workbooks("Copy_of_data.xlsm").Worksheets("Worksheet").Range("A1:A63").Value
    wb2ws2 = Workbooks("Copy_of_data_to_be_compared.xlsm").Worksheets("Archive").Range("A1:A23067").Value

    For i = LBound(wb1ws1) To UBound(wb1ws1)
        If wb1ws1(i, 1) = wb2ws2(i, 1) Then
            blnSame = True
        End If
    Next i

    If blnSame = True Then
        Sheets(sheetName).Cells(lRow, "A").Interior.ColorIndex = 3  'Set Color to Red'
    End If
End Sub
&#13;
$(document).on('click', 'input[name="ownorwant"]', function(){
    if($(this).val() == 'own'){
        $(this).closest('tbody').find('.child1').show();
    }else{
        $(this).closest('tbody').find('.child3').show();
    }
});
&#13;
&#13;
&#13;