<html xmlns="HTTP://www.w3.org/1999/xhtml">

<head runat="server">
<title></title>

 

<script type="text/javascript">
function convertFormat(txtbox) {
if (txtbox != null) {
var txtvalue = txtbox.value.replace("$", "");
txtvalue = txtvalue.replace("NaN", "");
txtvalue = txtvalue.replace(",", "");
if (isNaN(txtvalue) || txtvalue=="") {
txtbox.value = '';
//alert('請輸入數位');
}
else
{
var a = new Number();
a = Number.parseInvariant(txtvalue);
txtbox.value = a.localeFormat("c");
}
}
}
</script>

 

</head>
<body>
<form id="form1" runat="server">
<div>
<asp:ScriptManager ID="ScriptManager1" runat="server">
</asp:ScriptManager>
<asp:TextBox ID="TextBox1" runat="server"></asp:TextBox>
</div>
</form>
</body>
</html>




.aspx.cs

 

protected void Page_Load(object sender, EventArgs e)
{
this.TextBox1.Attributes.Add("onblur", "convertFormat("+this.TextBox1.ClientID+")");
}

 

PS:如需要小數位到4位,則c改為c4,以此類推
arrow
arrow
    全站熱搜

    戮克 發表在 痞客邦 留言(0) 人氣()