【问题标题】:set value in text box not more than 2 decimal places在文本框中设置的值不超过小数点后 2 位
【发布时间】:2016-01-21 06:48:25
【问题描述】:

我有一个文本框,允许用户用小数键入值。如何在文本框中设置只能输入2位小数。现在,用户可以输入超过 2 个小数位。下面是文本框的代码:

<td><b>Payment Amount:</b></td>
                            <td colspan="2">
                                <asp:TextBox ID="txtPayment" runat="server" Enabled="true" CssClass="form-control"/>
                                <asp:RequiredFieldValidator ID="rfvPayment" runat="server" ControlToValidate="txtPayment" ValidationGroup="SubmitGroup" Display="Dynamic" ErrorMessage="* Please fill in this section" />
                                <asp:RangeValidator ID="rgPayment" runat="server" ControlToValidate="txtPayment" Display="Dynamic" Type="Double"/>
                            </td>

对于文本框,在 id=rgPayment 上,我使用 rangevalidator 来验证值。 代码如下:

protected void lnkbtnB2CProceed_Click(object sender, EventArgs e)
    {
        rgPayment.MaximumValue = "30000";
        rgPayment.MinimumValue = "1";
        txtPayVia.Text = "Retail Banking";
        if (CheckAmount())
        {
            Proceed(Resources.Default.FPXMsgTokenB2C);
            trSupportedChannel.Visible = false;
        }
    }

    protected void lnkbtnB2BProceed_Click(object sender, EventArgs e)
    {
        rgPayment.MaximumValue = "1000000";
        rgPayment.MinimumValue = "2";
        txtPayVia.Text = "Corporate Banking (FPX)";
        if (CheckAmount())
        {
            Proceed(Resources.Default.FPXMsgTokenB2B);
            trSupportedChannel.Visible = false;
        }
    }

谢谢

【问题讨论】:

  • 考虑加一个问号,我看了好几遍才发现你在问问题。

标签: c# asp.net .net vb.net


【解决方案1】:

您可以下载JQuery numeric mask plugin 并将其引用添加到您的页面上。然后使用

$('[id*="txtPayment"]').numeric({ decimal : ".",  negative : false, scale: 2 });

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2016-04-27
    • 1970-01-01
    • 1970-01-01
    • 2020-06-09
    • 1970-01-01
    • 2020-07-24
    • 2011-01-13
    相关资源
    最近更新 更多