最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

javascript - AutoNumeric - removes received values - Stack Overflow

programmeradmin6浏览0评论

I use autoNumeric. Data that is added to the input is cleared when you hover the input element. Why are the values ​​cleared? How to fix it? 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=".3.1/jquery.min.js"></script>
<script src="/[email protected]"></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 />

I use autoNumeric. Data that is added to the input is cleared when you hover the input element. Why are the values ​​cleared? How to fix it? 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./ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<script src="https://cdn.jsdelivr/npm/[email protected]"></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 />

Share Improve this question edited Jul 7, 2019 at 16:05 MBaas 7,5487 gold badges50 silver badges66 bronze badges asked Jan 10, 2019 at 12:37 ДмитрийДмитрий 2942 silver badges14 bronze badges 1
  • 1 Where's the question? – CodeBlooded Commented Jan 10, 2019 at 13:04
Add a ment  | 

1 Answer 1

Reset to default 10

Need to add property watchExternalChanges.

Defines if the AutoNumeric element should watch external changes made without using .set()

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

评论列表(0)

  1. 暂无评论