gpt4 book ai didi

javascript - AutoNumeric - 删除收到的值

转载 作者:行者123 更新时间:2023-11-30 14:12:43 25 4
gpt4 key购买 nike

我使用自动数字。当您将鼠标悬停在 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 />

最佳答案

需要添加属性watchExternalChanges

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

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

关于javascript - AutoNumeric - 删除收到的值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/54128903/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com