【发布时间】:2021-11-22 22:33:27
【问题描述】:
我有一个 Currency Converter ,由两个字段和一个按钮组成。在第一个字段中,我输入要转换的金额,在第二个字段中,我得到转换的结果。 问题是: 当我在第一个字段中键入文本时,如何使用转换结果清理第二个字段中的文本?使用 Javascript / Jquery 函数?
提前致谢。
这是我的代码:
function convertiLireInEuro() {
var importoInserito = $('#txtLireEuro').val();
importoInserito = importoInserito.replace(/,/g, '.');
var lire = parseFloat(importoInserito)
var euro = lire * 1000 / 1936.27
euro = euro.toFixed(2);
euro = Math.round(euro);
$('#txtConversione').val(euro); }
HTML:
<input type="text" id="txtLireEuro" name="txtLireEuro" style="text-align:right" onkeypress="return onlyNumbers(event);" /> 000 ₤
<input value="Converti in Euro" type="button" id="btnLireEuro" name="btnLireEuro" style="margin-left: 20px" onclick="convertiLireInEuro();highlightAndCopyText();"/>
<input type="text" id="txtConversione" name="txtConversione" style="text-align:right;margin-left:20px" readonly /> €
<span class="Label" style="margin-left:12px">(importo già arrotondato all’intero e incollabile nel campo desiderato)</span>
【问题讨论】:
-
请阅读 How to Ask,在 SO 或 google 上进行一些搜索,尝试编码,如果您卡在这里发帖 minimal reproducible example
-
分享你的代码
-
如果任何答案解决了您的问题,请考虑接受它作为答案
标签: javascript c# html jquery css