Javascript 启用文本框oncheck复选框数组

Javascript 启用文本框oncheck复选框数组,javascript,arrays,textbox,Javascript,Arrays,Textbox,我一直在想如何在使用javascript检查文本框对应的复选框时启用文本框数组 这是我的密码: $line_util3 = "Select id_code,description from WEBLOAN_SERVER.webloan.dbo.mis_group where pid_code='$list_count' and group_no = '0' and child_node = '1' "; $stmt_line_util3=sqlsrv_query($conn, $

我一直在想如何在使用javascript检查文本框对应的复选框时启用文本框数组

这是我的密码:

    $line_util3 = "Select id_code,description from WEBLOAN_SERVER.webloan.dbo.mis_group where pid_code='$list_count' and group_no = '0' and child_node = '1' ";
    $stmt_line_util3=sqlsrv_query($conn, $line_util3);

    if(!$stmt_line_util3) {
        die( print_r( sqlsrv_errors(), true));
        }

    sqlsrv_execute($stmt_line_util3);

    while ($imps_row1 = sqlsrv_fetch_array($stmt_line_util3,SQLSRV_FETCH_ASSOC))

    {

    echo "<tr>";
    echo "<td><input type='checkbox' name='op[]'></td>";
    echo "<td>" . $imps_row1['id_code'] . " - " . $imps_row1['description'] . "</td>";
    echo "<td><input type='text' disabled='disabled' name='txt[]'></td>";
    echo "</tr>";

    }
$line\u util3=“从WEBLOAN\u SERVER.WEBLOAN.dbo.mis\u组中选择id\u代码、说明,其中pid\u代码='$list\u count',组\u no='0',子\u节点='1';
$stmt\u line\u util3=sqlsrv\u查询($conn,$line\u util3);
如果(!$stmt\u line\u util3){
模具(打印错误(sqlsrv_errors(),true));
}
sqlsrv_execute($stmt_line_util3);
而($imps_row1=sqlsrv_fetch_数组($stmt_line_util3,sqlsrv_fetch_ASSOC))
{
回声“;
回声“;
echo“$imps_row1['id_code']”-“$imps_row1['description']”;
回声“;
回声“;
}

非常感谢您的帮助

添加一个onclick事件以调用javascript函数到您的复选框,然后将id分配给您要禁用或启用/禁用或显示的不同文本框。在下面的代码中,我将启用id为“tpnr”的文本框,并禁用其他文本框(id:bs,as)


职能(a){
document.getElementById(“tpnr”).style.position=“static”;
document.getElementById(“tpnr”).style.top=“0px”;
document.getElementById(“bs”).style.position=“绝对”;
document.getElementById(“bs”).style.top=“-10000px”;
document.getElementById(“as”).style.position=“绝对”;
document.getElementById(“as”).style.top=“-10000px”;
}

试试这个,我希望这会对你有所帮助。它使用jQuery

$(document).on('click', 'input[name="op[]"]', function () {
    var checked = $(this).prop('checked');// true or false
    if (checked) {
        $(this).parents('tr').find('td input[type="text"]').removeAttr('disabled');
    }
    else {
        $(this).parents('tr').find('td input[type="text"]').attr('disabled', 'disabled');
    }
});

这里更新了

我添加了一个代码。如果您有任何疑问,请告诉我。文本框是动态添加的。。。我不能为每个文本框分配一个id,我只能为所有文本框使用一个id,但使用arrayu可以在while循环中动态分配id,如t1、t2、t3等。再获取一个变量,用while循环递增,并相应地将其分配为特定复选框的id。我还需要为此下载jquery插件吗?如果是,我在哪里可以下载它。。。谢谢@biosHere我已经更新了答案,请检查。
$(document).on('click', 'input[name="op[]"]', function () {
    var checked = $(this).prop('checked');// true or false
    if (checked) {
        $(this).parents('tr').find('td input[type="text"]').removeAttr('disabled');
    }
    else {
        $(this).parents('tr').find('td input[type="text"]').attr('disabled', 'disabled');
    }
});