启用文本框选中复选框数组

Enable Textbox oncheck checkbox Array

本文关键字:复选框 数组 文本 启用      更新时间:2023-09-26

我一直在弄清楚在使用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>";
    }

非常感谢您的帮助

试试这个,希望这对你有帮助。它使用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');
    }
});

这是更新的演示

添加一个onclick事件以调用javascript函数到您的复选框,然后将id分配给要禁用或启用/disaapear或 appear.in 以下代码的不同文本框我正在启用ID为"tpnr"的文本框并禁用其他文本框(id:BS,as)

<script type="text/javacript">
function(a){
    document.getElementById("tpnr").style.position = "static";
    document.getElementById("tpnr").style.top = "0px";
    document.getElementById("bs").style.position = "absolute";
    document.getElementById("bs").style.top = "-10000px";
    document.getElementById("as").style.position = "absolute";
    document.getElementById("as").style.top = "-10000px";
}
</script>