jQuery val()没有返回正确的值,而是返回了一个被截断的值

时间:2018-12-08 09:08:04

标签: jquery

我有以下代码(用于滑块):

<form name="volume">
  Volume(investor transactions)
 <output name="volumeOutputName" id="volumeOutputId" style="float:right;" >306789</output> <input type="range" name="volumeInputName" id="volumeInputId" value="306789" min="250000" max="1000000" oninput="volumeOutputId.value = volumeInputId.value" class="slider" step="50000">  
&nbsp;
</form>

在js文件中,我这样做:

var Ke=$("#volumeInputId").val();
console.log(Ke);

输出为300000,而不是应有的306789。为什么?

1 个答案:

答案 0 :(得分:3)

step=50000参数中将step=1更改为input,否则将滑块的精度限制为50,000。

下面的示例给出了您要寻找的答案,我还添加了一些每次更改值时都会打印到控制台的jquery,以便您进行测试。

var Ke=$("#volumeInputId").val();
console.log(Ke);

$("#volumeInputId").change( function() {
      console.log($(this).val());
});
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.3.1/jquery.min.js"></script>
<form name="volume">

Volume(investor transactions) <output name="volumeOutputName" id="volumeOutputId" style="float:right;" >306789</output> <input type="range" name="volumeInputName" id="volumeInputId" value="306789" min="250000" max="1000000" oninput="volumeOutputId.value = volumeInputId.value" class="slider" step="1">                   &nbsp;
</form>

相关问题