我想检查给定的结果是否等于无穷大。我怎样才能正确检查它?
<input type="text" name="answer" id="t" onkeyup="withoutLat(this);withoutCyr(this);checkInfinity(this);" placeholder="Enter data" autofocus>
function checkInfinity(value)
{
var value = calculator.answer.value;
if (value == Number.POSITIVE_INFINITY || value == Number.NEGATIVE_INFINITY)
{
alert("Помилка ділення на нуль")
}
}
答案 0 :(得分:3)
isFinite(12) //true
isFinite(12/0) //false
答案 1 :(得分:0)
var result = 10 / 0;
if (result === Infinity) {
alert('Atata!')
}
检查出来
https://developer.mozilla.org/ru/docs/Web/JavaScript/Reference/Global_Objects/Infinity
和jsfidle为你