2 回答

TA貢獻1853條經驗 獲得超18個贊
我猜你的問題是你不是分配一個由那些事件處理程序執行的函數,而是執行該函數,并且由于convert()
不返回函數,處理程序將不執行任何操作
嘗試
etherUnits.oninput = convert

TA貢獻1846條經驗 獲得超7個贊
你可以試試這是有效的。
HTML:
<div id="conversions">
<p>
<input type="number" id="etherAmount" value="2" onchange="covert()"> ether to <select id="etherUnits"
oninput="convert()">
<option id="wei" value="wei">Wei</option>
<option id="mwei" value="mwei">Mwei/Lovelace/Picoether</option>
<option id="gwei" value="gwei">Gwei/Shannon/Nanoether/Nano</option>
<option id="szabo" value="szabo">Szabo/Microether/Micro</option>
<option id="finney" value="finney">Finney/Milliether/Milli</option>
<option id="ether" value="ether">Ether</option>
<option id="kether" value="kether">Kether/Grand</option>
<option id="mether" value="mether">Mether</option>
<option id="gether" value="gether">Gether</option>
<option id="tether" value="tether">Tether</option>
<input type="submit" value="Convert" id="convert" onclick="convert()">
</select>
</p>
</div>
<div id="resultsContainer">
<p id="results"></p>
</div>
JS:
const converter = require("ethereumjs-units")
let etherUnits = document.getElementById("etherUnits")
let etherAmount = document.getElementById("etherAmount")
let convertButton = document.getElementById("convert")
let results = document.getElementById("results")
//Takes value of ether input box and converts it
function convert() {
//value of "convert to" box
let etherUnitVal = etherUnits.options[etherUnits.selectedIndex].value
results.innerHTML = converter.lazyConvert(etherAmount.value.toString() + " eth", etherUnitVal)
}
我只是更改并添加了 oninput,onchange 到相應的塊而不是在 js 中
添加回答
舉報