我想比较两个输入 minimumN 和 maximumN,并在不满足逻辑时显示警报,我有以下代码:
HTML:
<table>
<tr>
<th>Minimum N</th>
<td>
<input id="minN" onkeyup="MinimumNValidate()" type="text" maxlength="50">
</td>
<th>Maximum N</th>
<td>
<input id="maxN" onkeyup="MaximumNValidate()" type="text" maxlength="50">
</td>
</tr>
</table>
Javascript:
function MinimumNValidate() {
var min = document.getElementById("minN").value;
var max = document.getElementById("maxN").value;
if (min > max) {
alert("Minimum value must be lesser than maximum value.");
}
}
function MaximumNValidate() {
var min = document.getElementById("minN").value;
var max = document.getElementById("maxN").value;
if (max < min) {
alert("Maximum value must be greater than minimum value.");
}
}
但这不起作用,即使 minN 小于 maxN 也会显示警报,您能指出我的代码中的错误吗?