Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/418.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_Checkbox - Fatal编程技术网

Javascript 在与复选框相同的表行上查找隐藏的输入值

Javascript 在与复选框相同的表行上查找隐藏的输入值,javascript,jquery,html,checkbox,Javascript,Jquery,Html,Checkbox,我有一张表格,里面有复选框,我想知道两件事 复选框的ID 同一表行上隐藏字段的ID 所以我在每一行中都有一个隐藏字段,我想知道这个值是什么 我可以从Fiddle中看到的复选框是GridView1\uuuCtl3\uChkout,但是我希望jquery在同一个表行中找到隐藏字段的值 我看到GridView1\uuuCTL2\uHNDTXTID值是3601,但我将有许多行 小提琴--> jquery $('.out').on('change', function () { $(this).c

我有一张表格,里面有复选框,我想知道两件事

  • 复选框的ID
  • 同一表行上隐藏字段的ID
  • 所以我在每一行中都有一个隐藏字段,我想知道这个值是什么

    我可以从Fiddle中看到的复选框是GridView1\uuuCtl3\uChkout,但是我希望jquery在同一个表行中找到隐藏字段的值

    我看到GridView1\uuuCTL2\uHNDTXTID值是3601,但我将有许多行

    小提琴-->

    jquery

    $('.out').on('change', function () {
        $(this).closest('tr').find('.out').not(this).prop('checked', false);
        console.log(this.id);
        //what is the hidden field value in same row?
    });
    $('.yesno').on('change', function () {
        $(this).closest('tr').find('.yesno').not(this).prop('checked', false);
         //what is the hidden field value in same row?
    });
    
    console.log向我显示ID

    <table>
    <tr>
        <td style="width:5px;">
            <input type="hidden" name="GridView1:_ctl2:hndTxtId" id="GridView1__ctl2_hndTxtId" value="3601">
        </td>
        <td style="width:50px;">    <span id="GridView1__ctl2_lblVehicle0">413</span>
    
        </td>
        <td style="width:150px;"> <span id="GridView1__ctl2_lblName2">LONG</span>
    
        </td>
        <td style="width:100px;"> <span id="GridView1__ctl2_lblEquip2">BKT/TDR/M</span>
    
        </td>
        <td style="width:150px;">   <span id="GridView1__ctl2_lblScheduleb">0600-1430</span>
    
        </td>
        <td style="width:50px;"> <span id="GridView1__ctl2_lblScheduleOrig2">8</span>
    
        </td>
        <td style="width:150px;"> <span id="GridView1__ctl2_lblTimeOn"></span>
    
        </td>
        <td style="width:150px;"> <span id="GridView1__ctl2_lblTimeOff"></span>
    
        </td>
        <td>
            <input id="GridView1__ctl2_chkOut" type="checkbox" name="GridView1:_ctl2:chkOut" checked="checked" class="out">
        </td>
        <td>
            <input id="GridView1__ctl2_chkYes2" type="checkbox" name="GridView1:_ctl2:chkYes2" checked="checked" class="yesno">
        </td>
        <td>
            <input id="GridView1__ctl2_chkNo2" type="checkbox" name="GridView1:_ctl2:chkNo2" class="yesno">
        </td>
        <td style="width:5px;">
            <input type="submit" name="GridView1:_ctl2:AddButton0" value="On" onclick="setDateTimeOn(this); return false;" language="javascript" id="GridView1__ctl2_AddButton0" class="btn-blue">
        </td>
        <td style="width:150px;">
            <input name="GridView1:_ctl2:txtStormTimeOn" type="text" value="9-15-2015 12:00" id="GridView1__ctl2_txtStormTimeOn">
        </td>
        <td style="width:5px;">
            <input type="submit" name="GridView1:_ctl2:OffButton" value="Off" onclick="setDateTimeOn(this); return false;" language="javascript" id="GridView1__ctl2_OffButton" class="btn-blue">
        </td>
        <td style="width:150px;">
            <input name="GridView1:_ctl2:txtStormTimeOff" type="text" value="9-15-2015 12:28" id="GridView1__ctl2_txtStormTimeOff">
        </td>
        <td style="width:500px;"> <span id="GridView1__ctl2_lblComments"></span>
    
        </td>
        <td style="width:500px;">
            <input name="GridView1:_ctl2:txtStormComments" type="text" value="testfasdfsdfasdfsadfasdfsadf" maxlength="200" id="GridView1__ctl2_txtStormComments" style="width:200px;">
        </td>
    </tr>
    <tr>
        <td style="width:5px;">
            <input type="hidden" name="GridView1:_ctl2:hndTxtId" id="GridView1__ctl2_hndTxtId" value="3601">
        </td>
        <td style="width:50px;">    <span id="GridView1__ctl3_lblVehicle0">215</span>
    
        </td>
        <td style="width:150px;"> <span id="GridView1__ctl3_lblName2">MORGAN</span>
    
        </td>
        <td style="width:100px;"> <span id="GridView1__ctl3_lblEquip2">BKT/TDR</span>
    
        </td>
        <td style="width:150px;">   <span id="GridView1__ctl3_lblScheduleb">0600-1430</span>
    
        </td>
        <td style="width:50px;"> <span id="GridView1__ctl3_lblScheduleOrig2">8</span>
    
        </td>
        <td style="width:150px;"> <span id="GridView1__ctl3_lblTimeOn"></span>
    
        </td>
        <td style="width:150px;"> <span id="GridView1__ctl3_lblTimeOff"></span>
    
        </td>
        <td>
            <input id="GridView1__ctl3_chkOut" type="checkbox" name="GridView1:_ctl3:chkOut" class="out">
        </td>
        <td>
            <input id="GridView1__ctl3_chkYes2" type="checkbox" name="GridView1:_ctl3:chkYes2" class="yesno">
        </td>
        <td>
            <input id="GridView1__ctl3_chkNo2" type="checkbox" name="GridView1:_ctl3:chkNo2" class="yesno">
        </td>
        <td style="width:5px;">
            <input type="submit" name="GridView1:_ctl3:AddButton0" value="On" onclick="setDateTimeOn(this); return false;" language="javascript" id="GridView1__ctl3_AddButton0" class="btn-blue">
        </td>
        <td style="width:150px;">
            <input name="GridView1:_ctl3:txtStormTimeOn" type="text" id="GridView1__ctl3_txtStormTimeOn">
        </td>
        <td style="width:5px;">
            <input type="submit" name="GridView1:_ctl3:OffButton" value="Off" onclick="setDateTimeOn(this); return false;" language="javascript" id="GridView1__ctl3_OffButton" class="btn-blue">
        </td>
        <td style="width:150px;">
            <input name="GridView1:_ctl3:txtStormTimeOff" type="text" id="GridView1__ctl3_txtStormTimeOff">
        </td>
        <td style="width:500px;"> <span id="GridView1__ctl3_lblComments"></span>
    
        </td>
        <td style="width:500px;">
            <input name="GridView1:_ctl3:txtStormComments" type="text" maxlength="200" id="GridView1__ctl3_txtStormComments" style="width:200px;">
        </td>
    </tr>
    </table>
    
    
    413
    长的
    BKT/TDR/M
    0600-1430
    8.
    215
    摩根
    BKT/TDR
    0600-1430
    8.
    
    有关选择器的信息,请访问:

    拿着小提琴的一部分,它看起来:

    $tr = $(this).closest('tr');
    hidden = $tr.find('input[type="hidden"]');
    console.log(hidden);
    

    使用find方法,因为您已经在使用,但与
    'input[type=hidden]'
    一起使用:

    $('.out').on('change', function () {
        var $tr = $(this).closest('tr');
        $tr.find('.out').not(this).prop('checked', false);
        console.log(this.id);
        //what is the hidden field value in same row?
        var hiddenVal = $tr.find('input[type=hidden]').val();
        console.log(hiddenVal);
    });
    $('.yesno').on('change', function () {
        var $tr = $(this).closest('tr');
        $tr.find('.yesno').not(this).prop('checked', false);
        //what is the hidden field value in same row?
        var hiddenVal = $tr.find('input[type=hidden]').val();
        console.log(hiddenVal);
    });
    

    您已经获得了
    复选框的ID
    。要获取行的
    隐藏输入字段的值,请使用以下代码:

    $('.yesno').on('change', function () {
        $(this).closest('tr').find('input[type="hidden"]').val()
    });
    

    查看此

    您已经拥有复选框的id。您可以使用以下方法获取隐藏输入元素的id:

    var hiddenID = $(this).closest('tr').find('input[type=hidden]').prop('id');
    
    您可以得到相同字段的值,如下所示:

    var hiddenVal = $(this).closest('tr').find('input[type=hidden]').val();
    

    谢谢你的否决票,推特一定很有趣,因为我相信你没有问题,你知道所有完美的问题要问。:/我感谢所有其他人,他们从自己的知识中自由地给予帮助,帮助我和其他人。