[原创]利用DropDownlist来控制Textbox输入数字的精度
function check()
{
var dot=document.all("dll_Precision_Type").value;
// alert(dot);
var tv=document.all("txb_Price_Type").value;
if (isNaN(tv))
alert("此处应为数字类型");
else
{
var t=tv.substring(tv.indexOf(".")+1).length;
if (t!=dot) { alert("你的输入精度不够!"); return;}
}
}
{
var dot=document.all("dll_Precision_Type").value;
// alert(dot);
var tv=document.all("txb_Price_Type").value;
if (isNaN(tv))
alert("此处应为数字类型");
else
{
var t=tv.substring(tv.indexOf(".")+1).length;
if (t!=dot) { alert("你的输入精度不够!"); return;}
}
}
<body MS_POSITIONING="GridLayout">
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="dll_Precision_Type" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 56px"
runat="server">
<asp:ListItem Value="2">2位小数</asp:ListItem>
<asp:ListItem Value="3">3位小数</asp:ListItem>
</asp:DropDownList>
<asp:textbox id="txb_Price_Type" runat="server" CssClass="edit"></asp:textbox>
</form>
</body>
<form id="Form1" method="post" runat="server">
<asp:DropDownList id="dll_Precision_Type" style="Z-INDEX: 101; LEFT: 8px; POSITION: absolute; TOP: 56px"
runat="server">
<asp:ListItem Value="2">2位小数</asp:ListItem>
<asp:ListItem Value="3">3位小数</asp:ListItem>
</asp:DropDownList>
<asp:textbox id="txb_Price_Type" runat="server" CssClass="edit"></asp:textbox>
</form>
</body>
Private Sub Page_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
txb_Price_Type.Attributes.Add("onblur", "javascript:check();")
End Sub
txb_Price_Type.Attributes.Add("onblur", "javascript:check();")
End Sub