AutoNumeric-删除接收到的值

时间:2019-01-10 12:37:30

标签: javascript jquery ajax

我使用autoNumeric。将鼠标悬停在input元素上时,将清除添加到input的数据。为什么要清除这些值?如何解决? Demo

$('#thermForwardStream').focusout(function () {
            var thermForwardStream = $('#thermForwardStream').val();
            var thermBackStream = $('#thermBackStream').val();
            if (thermBackStream == "70" ) {
                $.ajax({
                    type: 'POST',
                    dataType: 'json',
                    data: { 'thermForwardStream': thermForwardStream, 'thermBackStream': thermBackStream },
                    url: '@Url.Action("GetDataAnnexY", "ThermLosses")',
                    success: function (data) {
                        $('#tempHeatExchangerOne').val(data.thermForwardStream);
                $('#tempHeatExchangerTwo').val(data.thermBackStream);
                    }
                });
            }
        });

const autoNumericOptions = {
allowDecimalPadding: "floats",
            decimalCharacter: ",",
            digitGroupSeparator: "",
            emptyInputBehavior: "zero"
};

new AutoNumeric('#thermForwardStream', autoNumericOptions);
new AutoNumeric('#thermBackStream', autoNumericOptions);
new AutoNumeric('#tempHeatExchangerOne', autoNumericOptions);
new AutoNumeric('#tempHeatExchangerTwo', autoNumericOptions);
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr.net/npm/autonumeric@4.1.0"></script>



<input class="form-control double" type="text" value="0" id="thermForwardStream" name="ThermForwardStream" required />

<input class="form-control double" type="text" value="70" id="thermBackStream" name="ThermBackStream" required />

<input class="form-control double" type="text" id="tempHeatExchangerOne" name="TempHeatExchangerOne" required />

<input class="form-control double" type="text" id="tempHeatExchangerTwo" name="TempHeatExchangerTwo" required />

1 个答案:

答案 0 :(得分:1)

需要添加属性watchExternalChanges

  

定义AutoNumeric元素是否应监视外部所做的更改   不使用.set()

 const autoNumericOptions = {
        allowDecimalPadding: "floats",
        decimalCharacter: ",",
        digitGroupSeparator: "",
        emptyInputBehavior: "zero",
        watchExternalChanges: true //!!!
    };