jQuery获取区间随机数

1.自定义函数

function getRandom(min,max){
    //x上限,y下限
    var x = max;
    var y = min;
    if(x<y){
        x=min;
        y=max;
    }
    var rand = parseInt(Math.random() * (x - y + 1) + y);
    return rand;
}

2.调用

alert(getRandom(100,200));

时间: 2024-08-24 08:52:44

jQuery获取区间随机数的相关文章

JQuery获取input type=&quot;text&quot;中的值的各种方式

<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml> <html xmlns="http://www.w3.org/1999/xhtml"> <head> <title>JQuery获取文本框的值</title> <meta http-equ

Javascript/jQuery 获取地址栏URL参数的方法

1.jquery获取url很简单,代码如下 window.location.href; 2.javascript获取url参数 function getUrlParam(name) { var reg = new RegExp("(^|&)"+ name +"=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象 var r = window.location.search.substr(1).match(reg);  /

jQuery获取Select选择的Text(非表单元素)和 Value(表单元素)(转)

jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...}); //为Select添加事件,当选择其中一项时触发 2. var checkText=$("#select_id").find("option:selected").text(); //获取Select选择的Text 3. var checkValue=$("#selec

jQuery获取Select选择的Text和 Value

jQuery获取Select选择的Text和Value: 语法解释: 1. $("#select_id").change(function(){//code...});   //为Select添加事件,当选择其中一项时触发 2. var checkText=$("#select_id").find("option:selected").text();  //获取Select选择的Text 3. var checkValue=$("#se

使用jquery获取radio的值

使用jquery获取radio的值,最重要的是掌握jquery选择器的使用,在一个表单中我们通常是要获取被选中的那个radio项的值,所以要加checked来筛选,比如有以下的一些radio项: 1.<input type="radio" name="testradio" value="jquery获取radio的值" />jquery获取radio的值<br /> 2.<input type="radio

Jquery获取select选中的option的文本信息

注意:下面用的$(this)代表当前选中的select框 第一种: $(this).children("option:selected").text(); 第二种: $(this).children("option:selected").html(); Jquery获取select选中的option的文本信息,布布扣,bubuko.com

使用jquery获取父元素或父节点的方法

jquery获取父元素方法比较多,比如parent(),parents(),closest()这些都能帮你实现查找父元素或节点,下面我们来一一讲解: <ul class="parent1"> <li><a href="#" id="item1">jquery获取父节点</a></li> <li><a href="#">jquery获取父元素&l

jquery获取checkbox被选中的值

只用一个循环,就可以找出被选中的checkbox的值 var s; $("[name = b]:checkbox").each(function () {                   if (this.checked) {                       s += $(this).val() + "|";                   }               });alert(s); 这样就可以了 jquery获取checkbox被

jQuery -&gt; 获取孩子节点

jQuery提供了很多方法来获取一个元素的direct descendant(直接后代). 最简单的方式是使用direct descendant combinator (>) 例如,如果要获取如下html代码中<div id="content">的直接孩子节点中的a元素,就可以直接使用 > 符号 <body> <div id="content"> <a href="http://www.jquery.c