我的jQuery代码有问题 我想随机化一个范围内的数字,我写了这个: jQuery代码:
$("#button").click(function() {
var numLow = $("#lownumber").value();
var numHigh = $("#highnumber").value();
var adjustedHigh = (parseFloat(numHigh) - parseFloat(numLow)) + 1;
var numRand = Math.floor(Math.random() * adjustedHigh) + parseFloat(numLow);
if ((isFinite(numLow)) && (isFinite(numHigh)) && parseFloat(numLow) <= parseFloat(numHigh) && (numLow != '') && (numHigh != '')) {
$("#random").text(numRand);
} else {
$("#random").text("Ops... an error!");
}
return false;
});
HTML页面:
<body>
<div class="text">Random</div>
<input type="text" id="lownumber" value="1">
<input type="text" id="highnumber" value="100">
<input type="submit" id="button" value="Generate!">
<div id="random"></div>
<script type="text/javascript" src="js/random.js"></script>
<script type="text/javascript" src="cordova.js"></script>
<script type="text/javascript" src="js/index.js"></script>
</body>
请帮助我! T.T
答案 0 :(得分:1)
假设struct
不是.val()
所以现在它有效..
.value()
&#13;
$("#button").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((isFinite(numLow)) && (isFinite(numHigh)) && parseFloat(numLow) <= parseFloat(numHigh) && (numLow != '') && (numHigh != '')){
$("#random").text(numRand);
} else {
$("#random").text("Ops... an error!");
}
return false;
});
&#13;