如何输出var f?

时间:2014-10-23 03:45:50

标签: javascript typescript output

我有一个按钮,在单击时运行特定功能。现在的问题是,一旦点击,我似乎无法获得在html页面上显示的特定值。如何输出var f以便它显示在html页面而不仅仅是在控制台中?

<!DOCTYPE html>
        <html>
        <head>
            <title>

    
    
        function get() {
    
          var tinput: HTMLInputElement = < HTMLInputElement > document.getElementById('total');
    
          var t: number = parseFloat(tinput.value);
    
          var f: number = t * .45;
    <!-- rounds var f to just two decimal places -->

          var f: number = Math.round(f * 100) / 100
    
    <!-- logs to the console-->

          console.log(f);
    
        }
    
    
    
        <!DOCTYPE html>
        <html>
    
        <head>
          <title></title>
        </head>
    
        <body>
    
          <div id="output">
            <input id="total" />

            <input value="click" onclick="get()" type="button" />
          </div>
    
    
    
          <script src="src/main.js"></script>
        </body>
    
        </html>
    
    
</title> </head> <body> <div id="output"> <input id="total" /> <input value="click" onclick="getTip()" type="button" /> </div> <script src="src/main.js"></script> </body> </html>

1 个答案:

答案 0 :(得分:0)

要在页面而不是控制台中显示它,请使用:

document.getElementById('total').innerHTML = f;