javascript - html输入框出现问题

标签 javascript html

我正在制作一个基本的美元转换器,用于 html/javascript 练习。 但是,当我选择欧元选项时,它的作用与比索选项相同。

<html>
    <head>
        <title>Currency Converter</title>
        <style>

        </style>
    </head>
    <body>
        <input id="amount"> </input>
        <p>usd Contverted to</p> 
        <p class="output"> </p>
        <select id="select"> <option value="1">Peso's</option> <option value="2">Euro's</option> </select>
        <p id="answer"> is </p>
        <input type="submit" value="Submit" onclick="run()"> 
        <script>
            function run() {
                var Amount = document.getElementById("amount").value;
                if (select = 1) {
                    document.getElementById("answer").innerHTML = "=-=-= " + Amount * 16.39  + "   =-=-=";
                } else if (select = 2) {
                    document.getElementById("answer").innerHTML = "=-=-= " + Amount * 0.9  + "   =-=-=";
                } else {
            }
        </script>
    </body>
</html>

最佳答案

你不是在比较选择,你是在设置它。

   if (select == 1) {
       document.getElementById("answer").innerHTML = ...
   } else if (select == 2) {
  • = -> 设置一个值
  • == -> 比较

关于javascript - html输入框出现问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/32004755/

相关文章:

javascript - 如何在 MAC safari 中按下后退按钮时强制刷新页面

javascript - 预加载器 : how to delete current loader div to show content div

javascript - 在 html 部分 View 中以模式显示 dataTable 时出现问题

html - 强制页面在 Internet Explorer 中打开(不是 Edge/Spartan)

javascript - php 表单不发送联系人电子邮件

javascript - 如何在 botium 中指定日期格式?

javascript - 在 IE9 中设置占位符 att

javascript - 单击 Chrome 中的浏览器通知时如何自动聚焦浏览器选项卡?

javascript - 如何使用 html class 或 ids 在任何地方显示内容

html - 相对水平地放置物体