任何帮助将不胜感激。我正在使用带有小数的 onChange 命令添加 JavaScript 字段,但是当 onChange 命令移回选项“NO”以删除数字(例如 1.7)时,它只删除 1.69999 而不是 1.7。
下面是我正在使用的 onChange 代码。
<div id="onewindow">
<label for="txtoneside" class="editor-label"><strong>1 Side </strong></label>
<div align="right">
<input type = "text" name = "txtoneside" id="txtoneside" value = "1.7" />
<select name="txtoneside_slider" id="txtoneside_slider" data-role="slider" data-mini="true" onChange="javascript: if(this.value=='yes'){ document.getElementById('txtgrandtotal').value= parseFloat(document.getElementById('txtgrandtotal').value) + parseFloat(document.getElementById('txtoneside').value); calculate()}
if(this.value=='no'){ document.getElementById('txtgrandtotal').value= parseFloat(document.getElementById('txtgrandtotal').value) - parseFloat(document.getElementById('txtoneside').value); calculate()}"/>
<option value="no">No</option>
<option value="yes">Yes</option>
</select>
</div>
<div id="twowindow">
<label for="txtoneside" class="editor-label"><strong>2 Side </strong></label>
<div align="right">
<input type = "text" name = "txttwoside" id="txttwoside" value = "19.3" />
<select name="txttwoside_slider" id="txttwoside_slider" data-role="slider" data-mini="true" onChange="javascript: if(this.value=='yes'){ document.getElementById('txtgrandtotal').value= parseFloat(document.getElementById('txtgrandtotal').value) + parseFloat(document.getElementById('txttwoside').value); calculate()}
if(this.value=='no'){ document.getElementById('txtgrandtotal').value= parseFloat(document.getElementById('txtgrandtotal').value) - parseFloat(document.getElementById('txttwoside').value); calculate()}" />
<option value="no">No</option>
<option value="yes">Yes</option>
</select>
</div>
<div id="grandtotal">
<label for="txtgrandtotal" class="editor-label"><strong>JOB TOTAL</strong></label>
<div align="right">
<input type = "text" name = "txtgrandtotal" id="txtgrandtotal" value = "0" />
</div>
</div>