html如何从单次计算中获得多个即时结果

时间:2013-10-12 19:03:59

标签: javascript jquery html css

是否可以通过此单一基本计算获得十几个结果?我在示例代码中有两个输出文本框;我怎样才能让这两个字段起作用?

<!DOCTYPE html>

<html lang = "en">

<head> 
    <title> multiple results calculation </title>
    <meta http-equiv="content-type" content="text/html; charset=utf-8"/>
    <link rel="style" href="css/main.css"  type"text/css"/>

    <!-- I need multiple results from single calculation! 

    <script type="text/javascript">
      function sum()
      {
         var width = document.multiple results.width.value;
         var height = document.multiple results.value;
         var sum = parseInt(width) * parseInt(height) /144; 
         document.getElementById('Calculate').value = sum;

         document.getElementById("results1").readOnly=true;
         document.getElementById("results2").readOnly=true;


         var result1= $1.99;
         var result2= $2.99;

         document.getElementById('Calculate').value = sum * result1;
         document.getElementById('Calculate').value = sum * result2; 

      }
    </script>       
    -->

</head>
    <body>

    <div> 
        <H2> Multiple instant results from single calculation</h2>
        <p>  the goal eventually is to have about a dozen results from this single calculation
    </div>  

        <form name="multiple results">

            <label for="width"> Width: </label>
            <input type="number" <id="width" maxlength="4" size="10" value=""/>

            <label for="height"> Height: </label>
            <input type="number" <id="height" maxlength="4" size="10" value=""/>

            <input type="button" name="button" value="Calculate" onClick="sum"/>

            <div>

            <label for="result1"> Result1: $ </label>
            <input type="number" id="result1" name="result1"/>

            <label for="result2"> Result2: $ </label>
            <input type="number" id="result2" name="result2"/>      
            </div>

        </form>
    </body>
</html>

1 个答案:

答案 0 :(得分:0)

我找到了一个解决方案,删除了第一个document.getElementById('Calculate')。value = sum;,将剩余的getElementById和输入类型更改为result,result2还将缺少的值=“”添加到输入中,不是必需的重命名Id帮助了我