我有一个JS代码来计算一个数字的倍数。我想在我的HTML文件中加入相同的内容。所以当我点击“提交”按钮时,它给了我答案。以下是我的代码:Javascript代码将被嵌入在HTML
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8">
<meta author="Shruti Paliwal">
<title>Project Euler Solutions</title>
<script language="javascript" type="text/javascript">
function multiples()
{
var i;
sum=0;
for(i=1;i<1000;i++)
{
if(i%3 === 0 || i%5 === 0)
{
sum+=i;
}
}
}
document.getElementById('sum').value = sum;
</script>
</head>
<body>
<h3>
<div id="header">
Project Euler
<sub>.net</sub>
</h3>
</div>
<br />
<br />
<p class="problem1" id="problem">
<b>
Multiples of 3 and 5
</b>
<div class="boundary" id="boundary">
<div class="content">
If we list all the natural numbers below 10 that are multiples of 3 or 5, we get 3, 5, 6 and 9. The sum of these multiples is 23.
<br />
Find the sum of all the multiples of 3 or 5 below 1000.
<br />
<br />
<form>
<input type="text" name="value">
<input type="button" onclick="sum()" value="Submit" />
</form>
</div>
</p>
</div>
</style>
</body>
</html>
需要帮助才能在我的网页上显示此代码的输出。计算倍数的逻辑在JS控制台上工作正常。但是,没有得到如何纳入2!
没有代码 – brk
您似乎没有在这方面付出太多的努力。 ; P – Matt
第37行是罪魁祸首 –