js生成随机编码并赋值给input文本框 | 您所在的位置:网站首页 › 怎么生成随机数并赋值给数组的值 › js生成随机编码并赋值给input文本框 |
效果图如下:
页面代码: 产 品 编 码 获取
js代码: function hq(){ //声明一个随机数变量,默认为1 var GetRandomn = 1; //js生成时间戳 var timestamp=new Date().getTime(); //获取随机范围内数值的函数 function GetRandom(n){ //由随机数+时间戳+1组成 GetRandomn=Math.floor(Math.random()*n+timestamp+1); } //开始调用,获得一个1-100的随机数 GetRandom("30"); //把随机数GetRandomn 赋给 input文本框.根据input的id document.getElementById('product_code').value = GetRandomn; //调试输出查看 //alert(GetRandomn); }
|
CopyRight 2018-2019 实验室设备网 版权所有 |