Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/406.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

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/file/3.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 在PHP foreach循环/数组中使用多个复选框时,单击复选框显示tr id_Javascript_Php_Jquery - Fatal编程技术网

Javascript 在PHP foreach循环/数组中使用多个复选框时,单击复选框显示tr id

Javascript 在PHP foreach循环/数组中使用多个复选框时,单击复选框显示tr id,javascript,php,jquery,Javascript,Php,Jquery,我有以下PHP/HTML代码: $PortingStatuses = array('Submitted' => 'Y', 'Accepted' => 'Y', 'Rejected' => 'Y', 'Complete' => '', 'Cancelled' => ''); foreach($PortingStatuses as $PortingStatus => $PortingChecked) { echo '<input ty

我有以下PHP/HTML代码:

$PortingStatuses = array('Submitted' => 'Y', 'Accepted' => 'Y', 'Rejected' => 'Y', 'Complete' => '', 'Cancelled' => '');
    foreach($PortingStatuses as $PortingStatus => $PortingChecked) {
        echo '<input type="checkbox" id="PortingStatus" value="PortingStatus_'.$PortingStatus.'"';
        if($PortingChecked == 'Y') {
            echo 'checked="checked"';
        }
        echo '/> '.$PortingStatus.'';
如何在复选框单击/取消单击时显示/隐藏每个tr

<input type=checkbox class=hidetr value=1>
<input type=checkbox class=hidetr value=2>
...
<tr id=tr1>...</tr>
<tr id=tr2>...</tr>

<script>
$(document).ready(function(){
    $('input.hidetr').on('click', function(){
        var trid = "tr" + $(this).val();
        if($(this).is(':checked')){
             $('#' + trid).show();
        }else{
             $('#' + trid).hide();
        }
    });
});
</script>

...
...
...
$(文档).ready(函数(){
$('input.hidetr')。在('click',function()上{
var trid=“tr”+$(this.val();
如果($(this).is(':checked')){
$('#'+trid).show();
}否则{
$('#'+trid).hide();
}
});
});
在jQuery中

$('#PortingStatus').click(function(){
    tr = this.value();
    if(this.checked==true)
        $('#'+tr+'').css('display','block');
    else
        $('#'+tr+'').css('display','none');     
});
使用Javascript:

function checkVal(elem){
    trId = elem.value;
    if(elem.checked == true)
        document.getElementById(''+trId+'').style.display='block'
    else
        document.getElementById(''+trId+'').style.display='none' 
}
在复选框中使用此选项:

使用
最近('tr')
将单击或更改事件添加到您的复选框中,该复选框将获取父tr,然后使用
隐藏()
函数隐藏tr行。为什么您有许多具有相同id的复选框
移植状态
function checkVal(elem){
    trId = elem.value;
    if(elem.checked == true)
        document.getElementById(''+trId+'').style.display='block'
    else
        document.getElementById(''+trId+'').style.display='none' 
}