简体   繁体   English

使用javascript的asp.net控件

[英]asp.net controls with javascript

I know this is probably a simple fix but I can't seem to figure out the issue here... 我知道这可能是一个简单的解决方法,但是我似乎无法在这里解决问题...

I am trying to disable withinthepast text box when RadioButton1 is clicked. 我试图在单击RadioButton1时禁用过去的文本框中。

<asp:RadioButton ID="RadioButton1" runat="server" Checked="True" GroupName="DateTimeQuery" OnClick="javascript:TimeRangeClickEvent()"/>
<asp:TextBox ID="withinthepast" runat="server" Text="1"></asp:TextBox>

<script>
        function TimeRangeClickEvent()
        {
            var radio1 = document.getElementById('<%=RadioButton1.ClientID%>').checked;                

            if (radio1 == true)
            {
                var within = document.getElementById('<%=withinthepast.ClientID%>').enabled = false;
            }
        }
    </script>

Any advice? 有什么建议吗?

try this 尝试这个

if (radio1.checked == true)
        {
            var within = document.getElementById('<%=withinthepast.ClientID%>').enabled = false;
        }

you can add attributes clientIdMode = static 您可以添加属性clientIdMode = static

The problem is probably with the "enabled" property. 问题可能出在“启用”属性上。 You can try this: 您可以尝试以下方法:

To enable a control: ctl.removeAttribute("disabled") 启用控件: ctl.removeAttribute("disabled")

To disable a control: ctl.setAttribute("disabled", "disabled") 禁用控件: ctl.setAttribute("disabled", "disabled")

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM