0

是否有可能从这个单一的基本计算中得到十几个结果?我在示例代码中有两个输出文本框;我怎样才能让这两个领域工作?

<!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>
4

1 回答 1

0

我通过删除第一个 document.getElementById('Calculate').value = sum; 找到了一个解决方案,将剩余的 getElementById 和输入类型更改为结果,并且 result2 还将缺失的 value="" 添加到输入中,这不是必需的,但重命名 Id 会有所帮助我

于 2013-10-15T21:54:18.163 回答