javascript语言弹出提示输入不能为空 我用的vs2005里的textbox控件,怎么样才能办到呢??我在网上搜的全是input(text)的控件啊,input控件又不知道该怎么把数据从里面提取出来,大家帮帮忙啊,尽量沾出代码啊, 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 textbox控件生成的html结果就是input控件<asp:TextBox onblur="if(this.value==''){ alert('不能为空');this.focus();}" 是的 <asp:TextBox runat="Server" ID="txtPassWord" onblur="if(this.value==''){ alert('密码不能为空!');this.focus();}"></asp:TextBox> 不行啊,说textbox没有onblur属性啊 <asp:TextBox runat="Server" ID="txtPassWord" onblur="if(this.value==''){ alert('密码不能为空!');this.focus();}"></asp:TextBox> <input id="Text1" type="text" onblur="if(this.value==''){ alert('密码不能为空!');this.focus();}"/> 什么意思啊?这样的话就会再多一个input的框啊,说详细点,本人菜鸟中的菜鸟,麻烦各位了 <asp:TextBox runat="Server" ID="txtPassWord" onblur="if(this.value==''){ alert('密码不能为空!');this.focus();}"></asp:TextBox>这个不行啊,说textbox没有onblur属性啊, 本帖最后由 net_lover 于 2012-03-24 17:31:48 编辑 能不能再我点button才触发这个事件啊,这样的话不管我点哪都会出啊 不行啊,这个方法只能在有一个textbox的时候才能行啊,我那个页面有好多的,它会一直“不能为空”,关都管不了啊 呵呵,onlur..alert(),亏你们想得出来,感叹号,加水印,或者在页面专门的区域提示(像IE9那样),怎么都可以啊楼主的意思是点击提交或者保存按钮以后弹出验证提示 假设控件为txtUserName,在提交按钮的click事件中写入:if(this.txtUserName.Text==""){ ScriptManager.RegisterStartupScript(this,this.GetType(),"", "alert('不能为空')", true); } 您这这个ScriptManager是什么意思啊? 哪来的啊?? 其实微软很多时候是把js脚本封装成服务器脚本,我们也可以如法炮制:public static class JSHelper { public static void Alert(string pValue) { pValue = MyHelper.ToString(pValue); string _s = "alert('" + pValue + "');"; JSHelper.Execute(_s); } public static void Execute(string pKey, string pjsString) { string _jsString = MyHelper.ToString(pjsString); string _Key = MyHelper.ToString(pKey); Page _thisPage = (Page)HttpContext.Current.Handler; ScriptManager.RegisterStartupScript(_thisPage, _thisPage.GetType(), _Key, _jsString, true); } public static void Execute(string pjsString) { JSHelper.Execute(MyHelper.ToString(Guid.NewGuid()), pjsString); } public static void SetFocus(string pClientId) { pClientId = MyHelper.ToString(pClientId); MyHelper.Assert(pClientId != "", new ArgumentException("参数pClientId不允许为空")); string _s = "var _focus = document.getElementById('" + pClientId + "');"; _s += "if(_focus)_focus.focus();"; JSHelper.Execute(Guid.NewGuid().ToString(), _s); } 于是14楼的代码可以写成:if(this.txtUserName.Text==""){ JSHelper.Alert("不能为空"); JSHelper.SetFocus(this.txtUserName.ClientId);//让这个控件获得焦点 } 引用 14 楼 microtry 的回复:假设控件为txtUserName,在提交按钮的click事件中写入:C# codeif(this.txtUserName.Text==""){ScriptManager.RegisterStartupScript(this,this.GetType(),"", "alert('不能为空')", true);}您这这个S…… 您这这个ScriptManager是什么意思啊? 哪来的啊?? ScriptManager参考MSDN:http://msdn.microsoft.com/zh-cn/library/system.web.ui.scriptmanager(v=vs.100).aspx 我看不懂啊大侠教教我呗,ScriptManager类是怎么建的啊 服务器端控件rander到页面也变成html了,但ID会做相应变化<asp:TextBox ID="txtText" ruant="Server"/>用document.getElementByID(<%=this.txtText.ClientID%>)就能取到这个控件的html元素了,然后按照html的操作就行了 【分享】由内到外螺旋旋转制作蜂巢 UINT32的使用方法有UINT32 year:12;这种样子的么 怎么把一个xml文件转化为 System.IO.Stream 流 关于C#里界面的问题 关于属性的用法 有谁知道上海的 中湾软件 怎么样啊? 哪款表格控件支持底部合计栏? 在北京搞C#.NET win form开发居然那么可怜!!你们呢? 一个c#开发的win程序在Xp上可以执行,在2003上不执行,怎么回事 怎么用C#控制某个文件夹的用户权限啊?实在不行就用C++吧。 中控二次开发 zkemkeeper ref out windows服务无法暂停,用.paused()方法
<asp:TextBox runat="Server" ID="txtPassWord" onblur="if(this.value==''){ alert('密码不能为空!');this.focus();}"></asp:TextBox> <input id="Text1" type="text" onblur="if(this.value==''){ alert('密码不能为空!');this.focus();}"/>
这个不行啊,说textbox没有onblur属性啊,
亏你们想得出来,
感叹号,加水印,或者在页面专门的区域提示(像IE9那样),怎么都可以啊
楼主的意思是点击提交或者保存按钮以后弹出验证提示
ScriptManager.RegisterStartupScript(this,this.GetType(),"", "alert('不能为空')", true);
}
public static class JSHelper {
public static void Alert(string pValue) {
pValue = MyHelper.ToString(pValue);
string _s = "alert('" + pValue + "');";
JSHelper.Execute(_s);
} public static void Execute(string pKey, string pjsString) {
string _jsString = MyHelper.ToString(pjsString);
string _Key = MyHelper.ToString(pKey);
Page _thisPage = (Page)HttpContext.Current.Handler;
ScriptManager.RegisterStartupScript(_thisPage, _thisPage.GetType(), _Key, _jsString, true);
}
public static void Execute(string pjsString) {
JSHelper.Execute(MyHelper.ToString(Guid.NewGuid()), pjsString);
} public static void SetFocus(string pClientId) {
pClientId = MyHelper.ToString(pClientId);
MyHelper.Assert(pClientId != "", new ArgumentException("参数pClientId不允许为空"));
string _s = "var _focus = document.getElementById('" + pClientId + "');";
_s += "if(_focus)_focus.focus();";
JSHelper.Execute(Guid.NewGuid().ToString(), _s);
}
if(this.txtUserName.Text==""){
JSHelper.Alert("不能为空");
JSHelper.SetFocus(this.txtUserName.ClientId);//让这个控件获得焦点
}
C# codeif(this.txtUserName.Text==""){
ScriptManager.RegisterStartupScript(this,this.GetType(),"", "alert('不能为空')", true);
}您这这个S……
http://msdn.microsoft.com/zh-cn/library/system.web.ui.scriptmanager(v=vs.100).aspx