0

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

    }

非常感谢你的帮助

4

2 回答 2

1

添加一个 onclick 事件以调用 javascript 函数到您的复选框,然后将 id 分配给您要禁用或启用/禁用或出现的不同文本框。在以下代码中,我启用 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>
于 2013-10-29T05:38:05.150 回答
1

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

这里更新了Demo

于 2013-10-29T05:39:31.247 回答