0

我有一个剑道数字文本框。此文本框允许正数和负数。

正如预期的那样,负数有一个“-”前缀。

是否可以在正数上添加“+”前缀?

我正在使用 ASP.NET MVC 5。这是一个代码示例:

@Html.Kendo().NumericTextBoxFor(model => model.PositveNegative).Step(0.25f)

对此的任何帮助将不胜感激。

谢谢。

阿布拉尔

4

2 回答 2

1

您可以使用 Change 和 Spin 事件处理程序。这是javascript版本的代码。

$("#inputID").kendoNumericTextBox({
                        format: "+#",
                        change: function() {
                          var value = this.value();                             
                          if(value>0) this.options.format="+#";
                          else this.options.format="#";

                        },
                       spin: function() {
                          var value = this.value();
                          if(value>0) this.options.format="+#";
                          else this.options.format="#";
                      }
                    });
于 2014-06-18T04:05:43.303 回答
0

使用 Cocococo 先生的回答作为起点,这里是适合您的 MVC 包装器版本:

 @(Html.Kendo().NumericTextBox().Name("Test").Step(0.25f)
.Events(events => events.Change("Testing").Spin("Testing"))
  )




    <script>

        function Testing()
        {

            var numeric = $("#Test").val();

            if (numeric > 0)
            {
                $("#Test").kendoNumericTextBox({ format: "+##.##", decimals: 2 });
            }
            else
            {
                $("#Test").kendoNumericTextBox({ format: "##.##", decimals: 2 });

            }
            console.log(numeric);
        }

    </script>

这适用于打字或使用微调器,应该会给你想要的结果。

于 2014-06-18T22:48:29.130 回答