禁用单选按钮如果表值为1或更多

时间:2015-03-03 13:46:14

标签: javascript jquery html

我有一个网页,当有&#39;是&#39;时,有一组单选按钮(是和否)。如果选中,则会显示隐藏的<div>。然后,用户会填充字段并点击“添加”字段。按钮然后显示在表格中。

此表还有一个&#39;删除&#39;链接。我想要&#39;不&#39;单选按钮变为“已禁用”#39;当表格中包含1个或多个条目,然后当表格为空时,通过使用&#39;删除&#39;重新启用。链接。

我想在JavaScript中执行此操作,因为我已经在页面上有一些当前禁用/启用功能的onclick

禁用“否”&#39;填充表格时,需要完成单选按钮,而不是onclick

当前JavaScript

    <script language="javascript" type="text/javascript">
    SetFocus("<%: ViewData["SetFocus"]%>");

    function CheckRadioOptions(obj, layers, showValue) {
        if (obj == document.getElementById("CTFYes")) {
            document.getElementById("Transfer").style.display = "none";
            document.getElementById("CTF").style.display = "block";
        }
        else {
            document.getElementById("Transfer").style.display = "block";
            document.getElementById("CTF").style.display = "none";
        }

        if (obj != null) {
            var value = "";
            for (var i = 0; i < obj.length; i++) { if (obj[i].checked) { value = obj[i].value; } }
            if (value == "") { value = obj.value; }
            if (value == showValue) { HideLayers(layers); } else { ShowLayers(layers); }
        }

    }

    window.onload = oneSelection();

    function oneSelection() {
        if (document.getElementById("TranYes").checked == true) {
            document.getElementById("CTFYes").disabled = true;
            document.getElementById("CTFYes").title = "This option has been disabled. You can re-enable it by selecting ‘No’ to the question above.";
            document.getElementById("CTFNo").checked = true;
        }
        if (document.getElementById("CTFYes").checked == true) {
            document.getElementById("TranYes").disabled = true;
            document.getElementById("TranYes").title = "This option has been disabled. You can re-enable it by selecting ‘No’ to the question below.";
            document.getElementById("TranNo").checked = true;
        }
        if (document.getElementById("TranNo").checked == true) {
            document.getElementById("CTFYes").disabled = false;
            document.getElementById("CTFYes").title = ""
        }
        if (document.getElementById("CTFNo").checked == true) {
            document.getElementById("TranYes").disabled = false;
            document.getElementById("TranYes").title = ""
        }
    }

    if ("<%=ViewData["CTF_Yes"].Equals(true)%>" == "True") {
        document.getElementById("Transfer").style.display = "none";
        document.getElementById("CTF").style.display = "block";
    }
    else {
        document.getElementById("Transfer").style.display = "block";
        document.getElementById("CTF").style.display = "none";
    }
</script>

仅限HTML HTML

<table class="table table-hover" id="transfertable" name="transfertable">
                <tr>
                    <th>Provider</th>
                    <th>Reference</th>
                    <th class="text-center">Approx. value</th>
                    <th>Action</th>
                </tr>
                <% 
                    Int32 c = 0;
                    foreach (AJBG.Web.Services.Entities.Client.Application.Products.IsaTransfer t in ISATransfers)
                    {
                       c++;
                 %>
                    <tr>
                        <td><%: Functions.Truncate(t.Manager, 10)%></td>
                        <td><%: Functions.Truncate(t.AccountNumber, 10) %></td>
                        <td class="text-right"><%: String.Format("{0:c}",t.ApproximateValue) %></td>
                        <td><a href="<%: Request.FilePath %>?id=<%: t.Identifier %>">Remove</a></td>
                    </tr>
                <% } %>
            </table>

1 个答案:

答案 0 :(得分:0)

找到答案。

if (document.getElementById("[TABLE_ID]").getElementsByTagName("tr").length >= 1)