小问题

liuyizhong 2008-11-03 03:22:31
一个TextBox 和一个 Button按纽,当TextBox中没有文字时Button按纽不可用,当TextBox中存在文字时Button按纽可用还请高手指教以下
...全文
81 4 打赏 收藏 转发到动态 举报
写回复
用AI写文章
4 条回复
切换为时间正序
请发表友善的回复…
发表回复
liuyizhong 2008-11-03
  • 打赏
  • 举报
回复
谢谢
jackyoung02 2008-11-03
  • 打赏
  • 举报
回复

<asp:TextBox ID="TextBox1" runat="server" onblur="button_enable()"></asp:TextBox>

文本框的事件改一下:改成onkeyup="button_enable()"

即:
<asp:TextBox ID="TextBox1" runat="server" onkeyup="button_enable()"></asp:TextBox>
liuyizhong 2008-11-03
  • 打赏
  • 举报
回复
对对要得就是这种效果,不过我要得是当TextBox控件中有文本时Button按纽立即可以运用,而不是离开TextBox后才可以用高手还可以在指点一下么一定重谢!!!!!!!
jackyoung02 2008-11-03
  • 打赏
  • 举报
回复

<html xmlns="http://www.w3.org/1999/xhtml" >
<head runat="server">
<title>Untitled Page</title>
<script language="javascript" type="text/javascript">

function SetButton()
{
var button = document.getElementById("Button2");

button.disabled = true;
}

function button_enable()
{
var text = document.getElementById("TextBox1").value;
var button = document.getElementById("Button2");
if(text != "")
{
button.disabled = false;
}
else
{
button.disabled = true;
}
}

</script>
</head>
<body onload="SetButton()">
<form id="form1" runat="server">
<div>
<asp:TextBox ID="TextBox1" runat="server" onblur="button_enable()"></asp:TextBox>
<asp:Button ID="Button2" runat="server" Text="Button" /></div>
</form>
</body>
</html>

1,979

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 其他语言讨论
社区管理员
  • 其他语言社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧