随机jQuery为Cordova应用程序

时间:2016-03-24 23:17:00

标签: javascript jquery cordova

我的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

1 个答案:

答案 0 :(得分:1)

假设struct不是.val()所以现在它有效..

&#13;
&#13;
.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;
&#13;
&#13;