Javascript 在文本框的onblur事件中绑定数据?
我有一个JavaScript函数来检查用户输入的值,它不应该超过来自数据库的值。我有这样的代码:Javascript 在文本框的onblur事件中绑定数据?,javascript,asp.net,Javascript,Asp.net,我有一个JavaScript函数来检查用户输入的值,它不应该超过来自数据库的值。我有这样的代码: <asp:TextBox ID="txtNoDays" runat="server" Width="49px" onblur="return NumericChk(this,'<%=v_days%>')"></asp:TextBox> 我建议您使用ASP.NET RangeValidator或CompareValidator控件 试试这个 加价 <head
<asp:TextBox ID="txtNoDays" runat="server" Width="49px" onblur="return NumericChk(this,'<%=v_days%>')"></asp:TextBox>
我建议您使用ASP.NET RangeValidator或CompareValidator控件 试试这个 加价
<head runat="server">
<title></title>
<script type="text/javascript">
function NumericChk(obj, val) {
if (obj.value > val) {
obj.focus();
return false;
}
return true;
}
</script>
</head>
<body>
<form id="form1" runat="server">
<asp:TextBox ID="TextBox1"
runat="server">
</asp:TextBox>
</form>
</body>
但在页面加载中,值是动态地来自数据库的。
protected void Page_Load(object sender, EventArgs e)
{
if (!IsPostBack)
{
int value = 10;
string handle=string.Format("return NumericChk(this,{0})",value);
TextBox1.Attributes.Add("onblur", handle);
}
}