简体   繁体   English

在屏幕上保持文本框,货币转换器-HTML5,Javascript

[英]Keeping Text box on screen, currency converter - HTML5, Javascript

<!doctype html>
<html lang="en>
<head>
    <meta charset="utf=8" />
    <title>Pound Euro Converter</title>
    <link rel="stylesheet" href="ptec.css" />
    <script type="text/javascript">

        var euro;

        function ETP(){
            euro = document.getElementById("euro").value;
            var pound = euro/1.17;
            document.getElementByID("answer").innerHTML = "Pounds = " + pound;
        }

    </script>



<body>

    <p id="answer"></p> 

    <input type="text" id="euro"/>

    <button onClick="ETP();">Convert</button>



</body>

</html>

The Problem is, after I convert my input (Euro) into Pounds, javascript writes the answer (in pounds) on the screen, but deletes everything else on the screen, including the input box. 问题是,在我将输入(欧元)转换为英镑后,javascript在屏幕上写下了答案(以磅为单位),但是删除了屏幕上的所有其他内容,包括输入框。 I want a Converter where The Input box remains on the screen the whole time, where it's just a matter of changing the number in the Input Box and clicking Convert. 我想要一个转换器,其中“输入”框始终保持在屏幕上,这只是更改“输入”框中的数字并单击“转换”的问题。 Do I have to put the input in some sort of loop? 我是否必须将输入放入某种循环中? I know if I could put the input box inside the Javascript function and if I kept looping the function it might work. 我知道是否可以将输入框放在Javascript函数内部,并且如果我不断循环执行该函数,则可能会起作用。 Has anyone got any ideas. 有没有人有任何想法。 The simplest way to keep the function running and the text box on the screen at all times. 使功能始终运行并始终在屏幕上显示文本框的最简单方法。 ~The same was as in google Translate, except with a currency converter basically. 〜基本上和货币转换器一样,与google Translate中的相同。

Just write the answer to an element. 只需将答案写到元素上即可。 The problem with document.write() is it destroys everything on the page. document.write()的问题是它破坏了页面上的所有内容。

HTML - somewhere to write the answer HTML-写答案的地方

<p id="answer"></p>

Javascript Java脚本

    function ETP(){
        euro = document.getElementById("euro").value;
        var pound = euro/1.17;
        document.getElementById("answer").innerHTML = "Pounds = " + pound;
    }

Demo 演示版

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM