Дми*_*рий 2 javascript ajax jquery autonumeric.js
我使用自动数字。input当您将鼠标悬停在input元素上时,添加到 的数据将被清除。为什么值被清除?如何解决?演示
$('#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);Run Code Online (Sandbox Code Playgroud)
<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 />Run Code Online (Sandbox Code Playgroud)
需要添加属性watchExternalChanges。
定义 AutoNumeric 元素是否应该监视不使用 .set() 所做的外部更改
const autoNumericOptions = {
allowDecimalPadding: "floats",
decimalCharacter: ",",
digitGroupSeparator: "",
emptyInputBehavior: "zero",
watchExternalChanges: true //!!!
};
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
785 次 |
| 最近记录: |