【发布时间】:2019-07-14 16:43:56
【问题描述】:
我正在尝试为一个类创建一些代码,提示用户输入三个数字,然后对这些数字进行一些计算,数学是对一个数字进行平方,将数字乘以 PI,然后将它们显示在适当的位置细胞。现在我的 onClick 没有工作,也没有提示给用户。我在那里有 min 和 max 函数,因为它是必需的 这是我的代码:
function promptForNumber(promptString, min, max) {
Array.prototype.max = function() {
return Math.max.apply(null, this);
};
Array.prototype.min = function() {
return Math.min.apply(null, this);
};
}
function populateRow(row) {
var number = promptForNumber("Enter your number");
row.cells[0].innerHTML = number;
row.cells[1].innerHTML = Math.pow(number, 2);
row.cells[2].innerHTML = (number / Math.PI).toFixed(4);
}
function isNotANumber(NaN) {
var isNotANumer = promptForAValidNumber("Please enter a
valid number ")
}
table,
th,
tr,
td {
border-collapse: collapse;
}
table {
width: 80%;
margin: 10%;
}
th {
width: 33%;
border: 2px solid black;
justify-content: space-evenly;
height: 25px;
background-color: white;
}
td {
border: 1px solid black;
padding: 1%;
text-align: center;
background-color: greenyellow;
}
<!DOCTYPE html>
<html lang="en">
<head>
<title>Assignment 2</title>
</head>
<body>
<table>
<tr>
<th>Number</th>
<th>Squared</th>
<th>Divided by Pi</th>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
<tr>
<td></td>
<td></td>
<td></td>
</tr>
</table>
</body>
</html>
【问题讨论】:
-
Right now my onClick is not working你的 onClick 函数在哪里? -
我在复制粘贴代码时忘记添加了,我正在玩弄它并删除了一点。它会出现在每个 tr 标头中,看起来像这样—— onClick="populateRow(this);"
标签: javascript html onclick prompt