1

テキストボックスに数値を入力すると、テキストボックスはこれらの数値を自動的に通貨に変換します.(12,345,654)

FilteredTextBoxExtender を使用できます

<ajaxToolkit:FilteredTextBoxExtender ID="ftbe" runat="server"
TargetControlID="TextBox3"         
FilterType="Custom, Numbers"
ValidChars="," />

しかし、ユーザーが数字を入力したときにカンマを自動的に追加したい。

4

3 に答える 3

6

私はJavaScriptコードを使用しています。

  function Comma(Num) { //function to add commas to textboxes
        Num += '';
        Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
        Num = Num.replace(',', ''); Num = Num.replace(',', ''); Num = Num.replace(',', '');
        x = Num.split('.');
        x1 = x[0];
        x2 = x.length > 1 ? '.' + x[1] : '';
        var rgx = /(\d+)(\d{3})/;
        while (rgx.test(x1))
            x1 = x1.replace(rgx, '$1' + ',' + '$2');
        return x1 + x2;
    }


<asp:TextBox ID="aPriceTextBox" runat="server" Width="100px"    onkeyup = "javascript:this.value=Comma(this.value);" />
于 2013-04-28T06:06:02.157 に答える
0

ここでは、マスク編集コントロールを使用することをお勧めします。

詳細については、StackOverflow に関するこの投稿を確認してください。通貨フィールドのテキスト ボックスを実装する方法を提案します。

codeplexでこのコンポーネントを参照することもできます。

于 2013-04-25T08:19:51.180 に答える
0


ここでajax maskedit エクステンダーを使用できます 。いくつかの例を次に示します。

<asp:ScriptManager ID="ScriptManager1" runat="server"></asp:ScriptManager>
        <asp:TextBox ID="TextBox1" runat="server" />
        <cc1:MaskedEditExtender runat ="server"
            TargetControlID="TextBox1"
            Mask="999,999,999,999"
            MessageValidatorTip="true"
            MaskType="Number"
            InputDirection="RightToLeft"
            AcceptNegative="Left"
            DisplayMoney="None"
            ErrorTooltipEnabled="True" />
于 2013-04-25T08:28:46.223 に答える