我的表單上有多個輸入欄位,某些欄位根據其他輸入欄位的復雜數學運算來生成數字。
示例輸入欄位
<td>/span><。 input class="form-control inputField" type="number" step="any" id="beUncorrectedGasRateWet" name="beUncorrectedGasRate[]" onblur="wetGasMeterRemake()" value=" > </td>>
我想改變的那個輸入上產生的數學運算
var tGasConsumption = document. getElementById("tGasConsumption70dry") 。
var gConsumptionMath = 0;
var tGasConsumptionMath = tGasConsumption;
if (gConsumption.value ! ="") gConsumptionMath = parseFloat(gConsumption.value)。
if (tGasConsumption.value ! ="") tGasConsumptionMath = parseFloat(tGasConsumption.value) 。
var totalCunGasRate = ((gConsumptionMath / tGasConsumptionMath) *3600) 。
document.getElementById("unGasRate").value = totalCunGasRate;
我想實作的是使一個輸入欄位可編輯,同時它也傳播數字。當我試圖改變已經在unGasRate輸入欄位上傳播的數字時,它不起作用,因為它回滾到它已經傳播的數字,同時onblur觸發。
<td>/span>< input class="form-control inputField gasConsumption" 型別="數字" 步驟="any" id ="gConsumption" name ="beGasConsumption[]" value=" > </td>>
<td>< input class="form-control editField gasConsumption" type="text default" id="tGasConsumption70dry" name="beTimeGasConsumption[]" value=" readonly> </td>>
<td>< input class="form-control inputField"/span> type="number" step="any" id="unGasRate" name="beUncorrectedGasRate[]" value=" > </td>>
我試圖做的是反向操作,做一些類似于unGasRate/3600的事情,這樣我就可以在其他2個輸入上得到輸入數字,在unGasRate上傳播結果,但這并不完全有效。
代碼要比這個大得多,但我在下面更新了一個問題的演示。
。calcRowWash = (function() {
var gConsumption = document.getElementById("gConsumption"/span>) 。
var tGasConsumption = document.getElementById("tGasConsumption">) 。
/* var atmPressure = document.getElementById("atmPressure");
var mPressire = document.getElementById("mPressire"); */
var defaultMath = 0;
var tGasConsumptionMath = tGasConsumption;
if (gConsumption.value ! = "") defaultMath = parseFloat(gConsumption.value)。
if (tGasConsumption.value ! = "") tGasConsumptionMath = parseFloat(tGasConsumption.value) 。
var totalC = ((defaultMath / tGasConsumptionMath) * 3600).toFixed(3) 。
/* var totalC2 = (288.15*(atmPressure mPressire) / (1013.25*(273.15 G21)); */
document.getElementById("unGasRate").value = totalC。
});
(G14)燃燒器壓力。<br>/span>
< input type="text" id="bPressure" name="bPressure" size="5"/span> tabindex="13"/span> /> <br> (G15)氣體消耗。<br> (G15)耗氣量:<br>
< input type="text"/span> id="gConsumption" name="gConsumption" size="gConsumption" size="gConsumption" string">"calcRowWash()" value=" maxlength="8" /> <br>(G16)耗氣時間。 <br> (G16)耗氣時間:<br>
< input type="text"/span> id="tGasConsumption" name="tGasConsumption" size="5" tabindex="14" value="120" value="120" onblur="calcRowWash()" maxlength="8" /> <br> (G17)未修正的氣體速率。
< input type="text" id="unGasRate" name="unGasRate" size="5" tabindex="13" onblur="calcRowWash()" maxlength="8" /> <br>>
<!--以上是作業正常! -->
<!--下面還沒有完成! -->
(G18)儀表校正系數:<br>
< input type="text"/span> id="mCorrectionFactor" name="mCorrectionFactor" size="5" tabindex="13" onblur="calcRowWash()" value=" /> <br>(G19)大氣壓力。<br> (G19)大氣壓力:<br>
< input type="text" id="atmPressure" name="atmPressure" size="5" tabindex="14" value=" /> <br> (G20)儀表壓力。
< input type="text" id="mPressire" name="mPressire" size="5" tabindex="13" onblur="calcRowWash()" /> <br>(G21)儀表溫度。 <br> (G21)儀表溫度:<br>
< input type="text" size="5" tabindex="13" onblur="calcRowWash()" value=" /> <br>
<!--需要進行數學運算** -->
(G22)氣體體積修正系數:<br>
< input type="text" id="gVolCorrectionFactor" name="gVolCorrectionFactor" size="5" tabindex="14" value=" /> <br>
<!--需要進行數學運算** -->
(G23)校正氣體速率:<br> br> br>
< input type="text" id="corGasRate" name="corGasRate" size="5" tabindex="13" onblur="calcRowWash()" /> <br>>
<!--需要進行數學運算** -->
(G24)Test Gas NET CV:<br>/span>
< input type="text" id="TestGasNetCv"/span> name="TestGasNetCv"/span> size="5" tabindex="13" onblur="calcRowWash()" value=" /> <br>
<!--需要進行數學運算** -->
(G25)實際凈熱輸入:<br>
< input type="text" id="actNetHeatInput" name="actNetHeatInput" size="5" tabindex="14" value=" /> <br>
<!-- 需要進行數學運算** -->
(G26)名義凈熱輸入。<br>
< input type="text"/span> id="devNominalNetHeatInp" name="devNominalNetHeatInp" size="5" tabindex="13" onblur="calcRowWash()" value="175" /> <br>>
<!--需要進行數學運算** -->
< input type="text"/span> id="devNominalNetHeatInp" name="devNominalNetHeatInp" size="5" tabindex="13" onblur="calcRowWash()" value=" /> <br>/span>
<iframe name="sif1" sandbox="allow-forms allow-modals allow-scripts" class="snippet-box-edit snippet-box-result" frameborder="0"></iframe>
uj5u.com熱心網友回復:
在運行你的邏輯之前測驗哪個元素被模糊了。
首先,給calcRowWash()函式添加一個引數,所以它看起來是這樣的:
function calcRowWash = (function(ev) {
然后,檢查ev的target成員變數的ID,并改變你的邏輯,看看會發生什么:
if(ev.target.id == "unGasRate") {
//logic here based on event target.
} else if (ev.target.id =="otherElement") {
//這個領域的其他邏輯。
} else if.
只要弄清楚每個目標之間的區別是什么,然后在里面寫具體的代碼,盡量不要重復你的代碼。你可能想再寫一個函式來重復邏輯。
轉載請註明出處,本文鏈接:https://www.uj5u.com/net/331843.html
標籤:
上一篇:如何從Ajax回應中獲取資料?
