禁用的文本框

发布于 2024-09-30 05:59:17 字数 969 浏览 0 评论 0原文

我写了这段代码。但它适用于 html 复选框和 txtbox。我想使用 asp.net txtbox 和 checkbox 具有相同的功能。如何做到这一点?

<script type="text/javascript">
    $(document).ready(function() {
    var checkbox = $('#notify');
        var textfield = $('#notifyemailaddress');
        checkbox.click(function() {
            if (checkbox.is(':checked')) {
                textfield.removeAttr("disabled");
                textfield.removeClass("email");
            }
            else {
                textfield.attr("disabled", "disabled");
                textfield.addClass("email");
            }
        });
    });
</script>
<div>
                               <input type="checkbox"  id="notify"/>
                              <label for="notify">Notify</label>
                              <input type="text" id="notifyemailaddress" disabled="disabled" class="email" style="width:25%" /> 
                             </div>

i hv written this piece of code. but it is for html checkbox and txtbox. i want to hv the same functionality with asp.net txtbox and checkbox.how to do it?

<script type="text/javascript">
    $(document).ready(function() {
    var checkbox = $('#notify');
        var textfield = $('#notifyemailaddress');
        checkbox.click(function() {
            if (checkbox.is(':checked')) {
                textfield.removeAttr("disabled");
                textfield.removeClass("email");
            }
            else {
                textfield.attr("disabled", "disabled");
                textfield.addClass("email");
            }
        });
    });
</script>
<div>
                               <input type="checkbox"  id="notify"/>
                              <label for="notify">Notify</label>
                              <input type="text" id="notifyemailaddress" disabled="disabled" class="email" style="width:25%" /> 
                             </div>

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

风流物 2024-10-07 05:59:18

您需要在 ASP.NET 上找到正确的 ID,为此,您可以使用 ASP.NET 控件的 ClientID。因此,您可以编写类似

 var checkbox = $('#<%=notify.ClientID%>');

Where <%=notify.ClientID%>, is print the Final rendered id of your control的内容,并且输入看起来像

<asp:CheckBox runat="server" id="notify" />

在asp.net 4上,您还可以使用静态id来避免ClientID,但请注意不要在同一页面上多次使用相同的控件 ID。您可以阅读更多内容: http://msdn.microsoft.com/en-us /library/1d04y8ss.aspx

You need to find the correct id on asp.net and to do that you can use the ClientID of your asp.net controls. So you write something like

 var checkbox = $('#<%=notify.ClientID%>');

Where <%=notify.ClientID%>, is print the final rendered id of your control, and the input is looks like

<asp:CheckBox runat="server" id="notify" />

On asp.net 4 you have also the ability to use static id to even avoid the ClientID, but take care to not use the same control id more than one time on the same page. You can read more on: http://msdn.microsoft.com/en-us/library/1d04y8ss.aspx

不醒的梦 2024-10-07 05:59:18

如果您选中服务器控件名称是notifyemailaddress,则使用以下命令:

var textfield = $('#<%= notifyemailaddress.ClientID %>');

If you checkbox server control name is notifyemailaddress then use this:

var textfield = $('#<%= notifyemailaddress.ClientID %>');
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文