请帮我找到这个代码的解决方案,我想在这个数字生成器中限制一个数字,例如 34。当有人通过按钮单击生成数字时,切勿与受限数字重合,例如 34 :) 谢谢
function IsNumeric(n){
return !isNaN(n);
}
$(function(){
$("#getit").click(function() {
var numLow = $("#lownumber").val();
var numHigh = $("#highnumber").val();
var adjustedHigh = (parseFloat(numHigh) - parseFloat(numLow)) + 1;
var numRand = Math.floor(Math.random()*adjustedHigh) + parseFloat(numLow);
if ((IsNumeric(numLow)) && (IsNumeric(numHigh)) && (parseFloat(numLow) <= parseFloat(numHigh)) && (numLow != '') && (numHigh != '')) {
$("#randomnumber").text(numRand);
} else {
$("#randomnumber").text("Careful now...");
}
return false;
});
$("input[type=text]").each(function(){
$(this).data("first-click", true);
});
$("input[type=text]").focus(function(){
if ($(this).data("first-click")) {
$(this).val("");
$(this).data("first-click", false);
$(this).css("color", "black");
}
});
});
和 HTML
<div id="page-wrap">
<img src="images/randomnumb.png" alt="get a random number between..." />
<input type="text" id="lownumber" value="1" />
and
<input type="text" id="highnumber" value="100" />
<br />
<button id="getit">Generate!</button>
<div id="randomnumber"></div>
</div>