在GridView 有个TextBox列 何用js 判断输入是否是数字 并且精确到2位小数,如果不对TextBox 变为红色并有提示框<asp:GridView ID="GVRoomList" runat="server" AllowSorting="True" PageSize="100" CellPadding="4" ForeColor="Black" GridLines="None" Width="100%" AutoGenerateColumns="False">
<Columns>
<asp:templatefield headertext="金额">
<itemtemplate>
<asp:TextBox ID="txtPRICE" runat="server" Width="60" BorderStyle="Groove"></asp:TextBox>
</itemtemplate>
<ItemStyle Width="60px" />
<HeaderStyle Font-Size="Small" ForeColor="Black" />
</asp:templatefield>
</Columns>
</asp:GridView>我不知道如何去实现,请教下各位高手 非常感谢!
<Columns>
<asp:templatefield headertext="金额">
<itemtemplate>
<asp:TextBox ID="txtPRICE" runat="server" Width="60" BorderStyle="Groove"></asp:TextBox>
</itemtemplate>
<ItemStyle Width="60px" />
<HeaderStyle Font-Size="Small" ForeColor="Black" />
</asp:templatefield>
</Columns>
</asp:GridView>我不知道如何去实现,请教下各位高手 非常感谢!
if(textbox.value为数字)
else
{textbox.style.backgroudcolor='red';}
<script>
function JS()
{
//根据需求进行写...
}
</script>然后在文本onblur="JS()"
<itemtemplate>
<asp:TextBox ID="txtPRICE" runat="server" Width="60" BorderStyle="Groove" onblue="JS"> </asp:TextBox>
</itemtemplate>
然后
<script type="text/javascript">
function JS()
{
//根据需求进行写...
}
</script>
{
var text1;
var sTest=/\d+.\d{2}$/;
if(sTest.test(text1.value)==false)
{
alert("Format error!")
}
}
if(textbox.value为数字)
else
{textbox.style.backgroudcolor='red';}
这样不行的,我那是个GridView 列 有多个textbox ID是不同的 而且是<asp:TextBox>控件 这样写document.getElementById("txtPRICE") 报缺少对象错误
{
var text1;
var sTest=/\d+.\d{2}$/;
if(sTest.test(text1.value)==false)
{
textbox.style.backgroudcolor='red';
}
}
{
if(obj.value=="")return;
var str=/^(\d+\d$)|(^[0-9]+d*\.\d{2}$)/;
if(!str.test(obj.value))
{
window.alert("输入数字不合法,正确的格式为100或100.12");
obj.style.cssText="background-clor:red";
obj.select();
}
else
{
obj.style.cssText="";
}
} protected void GridView1_RowDataBound(object sender, GridViewRowEventArgs e)
{
if (e.Row.RowType == DataControlRowType.DataRow || e.Row.RowType == DataControlRowType.Separator)
{
TextBox txtPrice = e.Row.FindControl("txtPRICE") as TextBox;
if (txtPrice != null)
{
txtPrice.Attributes.Add("onblur", "IsDecimal(this)");
}
}
}