【问题标题】:Text Input automatic decimal文本输入自动小数
【发布时间】:2017-05-31 23:47:37
【问题描述】:

如何使用小数点','自动输入文本?

<td><?= $form->field($model, 'Payment')->textInput(['maxlength' => 7, 'style' => 'width:120px;'])?></td>

【问题讨论】:

    标签: php yii textinput


    【解决方案1】:
    <td><?= $form->field($model, 'Payment')->textInput([
        'maxlength' => 7,
        'style' => 'width:120px;'
        'type' => 'number', // this will set input to decimal number format
        'step' => '0.0001' // and this
    ])?></td>
    

    【讨论】:

      【解决方案2】:
      <input type="number" id="decimalvalue" name="decimalvalue" onkeyup="setDecimalValue()">
      
      <script>
          function setDecimalValue() {
              var num = $('#decimalvalue').val();
              var n = num.toFixed(2);
              $('#decimalvalue').val(n);
          }
      </script>
      

      【讨论】:

        【解决方案3】:

        在 yii 我们有自定义数字格式选项。为此,我们必须重写现有的格式函数。

        您可以参考以下链接了解更多详情。 http://www.yiiframework.com/wiki/360/custom-number-formatting-or-decimal-separators-and-i18n/

        【讨论】:

          【解决方案4】:
          <input type="number" onchange="setTwoNumberDecimal" min="0" max="10" step="0.25" value="0.00" />
          
          function setTwoNumberDecimal(event) {
              this.value = parseFloat(this.value).toFixed(2);
          }
          

          【讨论】:

            猜你喜欢
            • 1970-01-01
            • 1970-01-01
            • 2015-11-01
            • 2012-11-14
            • 1970-01-01
            • 2012-11-23
            • 2022-01-19
            • 1970-01-01
            • 1970-01-01
            相关资源
            最近更新 更多