日期:2014-05-16  浏览次数:20413 次

求高人指导,jquery控制控件的禁用和启用状态
<script   type= "text/javascript ">
function   updae(onde)   {
    $( "#btnSubmit ").attr( "disabled ",   "false ");
}
</script>

<input     id= "e_name "   onblur= "return   updae(this); "     runat= "server "   onkeyup= "return   updae(this); "/>

<asp:Button   ID= "btnSubmit "   runat= "server "   Text= " "   CssClass= "btnSubmit "   Enabled= "false "   onclick= "btnSubmit_Click "   />


我想在光标离开文本框和键盘事件里把Button设为启用,jq应该怎么写呢?




------解决方案--------------------
HTML code
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title>无标题文档</title>
<script type="text/javascript" src="http://ajax.aspnetcdn.com/ajax/jQuery/jquery-1.7.2.min.js"></script>
<script type="text/javascript">
$(document).ready( function() {
    $("#e_name").bind({
        'click': function() { $("#btnSubmit").removeAttr("disabled"); },
        'keyup': function() { $("#btnSubmit").removeAttr("disabled"); }
    });
});
</script>
</head>

<body>
<input id= "e_name" type="text" /><button id="btnSubmit" disabled="disabled">BUTTON</button> 
</body>
</html>

------解决方案--------------------
HTML code

<!DOCTYPE HTML>
<html>
    <head>
        <meta charset="gb2312" />
        <title></title>
    </head>
    <body>
        失焦时禁用,按 ctrl + q 启用
        <input id="test" />
        <script>
            function $(el){
                return typeof el == 'string' ? document.getElementById(el) : el;
            }
            var obj = $('test');
            obj.onblur = function(){
                this.disabled = true;
            }
            document.onkeydown = function(e){
                e = window.event || e;

                if( e.ctrlKey && e.keyCode == 81 ){
                    obj.disabled = false;
                    obj.focus();
                }
            }
        </script>
    </body>
</html>