使用javascript和asp.net启用和禁用按钮 [英] Enable and disable button using javascript and asp.net
本文介绍了使用javascript和asp.net启用和禁用按钮的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在检查用户是否存在于数据库中(如果存在)我将消息显示为已存在的用户,然后我需要禁用注册按钮,如果不是我需要启用它。
I am checking if user exists in database if exists I am showing message as "existed user" and then I need to disable the signup button if not I need to enable it.
我无法启用和禁用注册按钮。
I am unable to enable and disable the sign Up button.
任何人都可以帮我解决此问题吗?
Can anyone help me in this issue?
这是我的代码:
<script type="text/javascript">
$(function () {
$("#<% =btnavailable.ClientID %>").click(function () {
if ($("#<% =txtUserName.ClientID %>").val() == "") {
$("#<% =txtUserName.ClientID %>").removeClass().addClass('notavailablecss').text('Required field cannot be blank').fadeIn("slow");
} else {
$("#<% =txtUserName.ClientID %>").removeClass().addClass('messagebox').text('Checking...').fadeIn("slow");
$.post("LoginHandler.ashx", { uname: $("#<% =txtUserName.ClientID %>").val() }, function (result) {
if (result == "1") {
$("#<% =txtUserName.ClientID %>").addClass('notavailablecss').fadeTo(900, 1);
document.getElementById(#<% =btnSignUp.ClientID %>').enabled = false;
}
else if (result == "0") {
$("#<% =txtUserName.ClientID %>").addClass('availablecss').fadeTo(900, 1);
document.getElementById('#<% =btnSignUp.ClientID %>').enabled = true;
}
else {
$("#<% =txtUserName.ClientID %>").addClass('notavailablecss').fadeTo(900, 1);
}
});
}
});
$("#<% =btnavailable.ClientID %>").ajaxError(function (event, request, settings, error) {
alert("Error requesting page " + settings.url + " Error:" + error);
});
});
</script>
推荐答案
不幸的是你的问题就像它们之间的区别一样小已启用
且已停用
Unfortunately your problem is something as small as the difference between enabled
and disabled
.enabled = true;
应该是:
.disabled = false;
这篇关于使用javascript和asp.net启用和禁用按钮的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文