2 回答
![?](http://img1.sycdn.imooc.com/545865620001c45402760276-100-100.jpg)
TA贡献1853条经验 获得超18个赞
我猜你的问题是你不是分配一个由那些事件处理程序执行的函数,而是执行该函数,并且由于convert()
不返回函数,处理程序将不执行任何操作
尝试
etherUnits.oninput = convert
![?](http://img1.sycdn.imooc.com/5458477300014deb02200220-100-100.jpg)
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 中
添加回答
举报