gpt4 book ai didi

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

转载 作者:行者123 更新时间:2023-11-28 12:13:35 25 4
gpt4 key购买 nike

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

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

最佳答案

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

关于javascript - html 如何从一次计算中获得多个即时结果,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/19338039/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com