启用和禁用按钮 [英] Enable and disable button

查看:119
本文介绍了启用和禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我看了很多例子能够在这里和在JavaScript中禁用按钮,jQuery和其中的任何为我工作的。

下面我绝望的境地。

 < ASP:文本框ID =MYTEXT=服务器的onkeyup =enableButton(这一点,3)/>
< ASP:按钮的ID =myButton的=服务器文本=搜索已禁用=禁用/>

和我的JavaScript

 <脚本类型=文/ JavaScript的>
            功能enableButton(控制字符){
                如果(control.value.length> =字符){
                    $('#则myButton')removeAttr(禁用)。
                }其他{
                    $('#则myButton')ATTR(已禁用,真)。
                }
            }
        < / SCRIPT>


  

修改


嘿家伙,我终于明白了!

我注册了我的javascript功能的LoadPage事件在codebehind通话

  mytext.Attributes.Add(安其preSS,enableButton('+ mytext.ClientID +',3,'+ mybutton.ClientID +' );

感谢大家,你们的时间!


解决方案

残疾人是一个属性,不是属性。

使用:

  $('#则myButton')丙(禁用,已禁用);

I looked many examples here of enabling and disabling a button in javascript with jquery and any of them worked for me.

Here my desperate situation.

<asp:TextBox ID="mytext" runat="server" onkeyup="enableButton(this, 3)"/>
<asp:Button ID="myButton" runat="server" Text="Search" disabled="disabled" />

and my javascript

        <script type="text/javascript">
            function enableButton(control, chars) {
                if (control.value.length >= chars) {
                    $('#myButton').removeAttr("disabled");
                } else {
                    $('#myButton').attr("disabled", true);
                }
            }
        </script>

EDIT

Hey fellows, finally I got it!

I registered the call of my javascript function in LoadPage event in the codebehind

mytext.Attributes.Add("onkeypress", "enableButton('" + mytext.ClientID + "',3,'" + mybutton.ClientID + "');"

Thank you all you guys for the time!

解决方案

Disabled is a property, not an attribute.

Use:

$('#myButton').prop("disabled", "disabled");

这篇关于启用和禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆