草庐IT

set_random_seed

全部标签

javascript - Select2.js v4.0 : how set the default selected value with a local array data source?

通过使用select2.jsv4插件,当我使用本地数组数据作为源时,如何设置默认选择值?以这段代码为例vardata_names=[{id:0,text:"Henri",},{id:1,text:"John",},{id:2,text:"Victor",},{id:3,text:"Marie",}];$('select').select2({data:data_names,});如何设置id3为默认选中值? 最佳答案 $('.select').select2({data:data_names,}).select2("val",3);

javascript - Math.floor(Math.random()) +1 实际上做了什么?

当你有Math.floor(Math.random()*10)+1时,它应该根据我的理解选择1-10之间的随机数。但是,当我将+1更改为高于或低于1的任何数字时,我得到相同的结果。为什么是这样?+1到底是什么意思? 最佳答案 随机数生成器产生的值在0.0+1偏移量的数字。通常你可以使用:Math.floor(Math.random()*N)+M这将生成M和M+N-1之间的值。demoFiddle 关于javascript-Math.floor(Math.random())+1实际上做了什

javascript - 解释 Math.floor(Math.random())

我看到很多地方都在使用Math.floor()和Math.random()喜欢下面$('a.random-color').hover(function(){//mouseovervarcol='rgb('+(Math.floor(Math.random()*256))+','+(Math.floor(Math.random()*256))+','+(Math.floor(Math.random()*256))+')';$(this).animate({'color':col,'paddingLeft':'20px'},1000);},function(){//mouseout$(thi

javascript - Chart.js 时间刻度 : set min and max on xAxes

如何在xAxes上设置最小值和最大值?它在yAxes上工作正常,但在xAxes上它没有显示任何行为。我的xAxes使用的是type:'time'。我的xAxis标签也使用了moment对象。但是当我删除类型时间并使用普通数字时它也不起作用。我使用的是Chart.js版本2.2.2。scales:{yAxes:[{ticks:{beginAtZero:false,}}],xAxes:[{type:'time',ticks:{min:moment(1471174953000),max:moment(1473853353000)}}]}Hereisthechart.jsTimeScaledo

Javascript "pre set"一个变量?

我正在尝试声明一个变量,其值是另一个当时未设置的变量。varadd=1+three;varthree=3;document.getElementById('thediv').innerHTML=add;//resultsin"NaN"http://jsfiddle.net/seSMx/1/有没有办法使用Jquery/Javascript来做到这一点? 最佳答案 你可以把add变成一个函数,http://jsfiddle.net/seSMx/3/functionadd(){return1+(three||0);}varthree=3;

javascript - Backbone : Id not being set to model

我尝试了以下方法来为我的模型设置一个id:varglobalCounter=1;varModel=Backbone.Model.extend({initialize:function(){this.id=globalCounter;globalCounter+=1;}});myModel=newModel();console.log(myMode.get('id'));//printsundefined如何为我的模型设置ID? 最佳答案 您需要使用set()代替函数(http://jsbin.com/agosub/1/);vargl

javascript - 影响 Math.random()

我正在寻找一种方法来影响Math.random()。我有这个函数来生成一个从最小值到最大值的数字:varrand=function(min,max){returnMath.floor(Math.random()*(max-min+1))+min;}有没有办法让它比中间的数字更容易得到低和高的数字?例如;rand(0,10)将返回比其余更多的0,1,9,10。 最佳答案 Isthereawaytomakeitmorelikelytogetalowandhighnumberthananumberinthemiddle?是的。您想要更改生

javascript - 如何在 JavaScript 中使用 Math.random 进行测试?

我有一个函数可以在最小值和最大值之间选择一个随机值。因此,当我进行测试时,我会测试该值是否介于最小值和最大值之间。但是由于我的应用程序出现了一些故障,因此测试有时会通过,有时会由于随机性而失败。覆盖/模拟Math.random()以返回0和1并测试我的值是否与最大值或最小值相同是个好主意吗?或者是否有更好的方法来测试JavaScript中的随机性?这是将用于创建随机数的函数:functionconstrain(min,max){returnMath.round(Math.random()*(max-min)+min)} 最佳答案 S

javascript - JsHint - 隐藏此消息 : ES5 option is now set per default

我正在使用gulp-jshint,下面的错误消息很烦人:ES5optionisnowsetperdefault如何删除它? 最佳答案 它只是告诉您这是默认设置,因此您无需将其添加为选项。查看.jshintrc文件并删除"es5":true。http://jslinterrors.com/es5-option-is-now-set-per-default 关于javascript-JsHint-隐藏此消息:ES5optionisnowsetperdefault,我们在StackOverfl

javascript - ionic 2 : Set interval

我尝试在.ts文件中设置一个间隔,但我不明白如何在间隔中使用同一文件中的函数。解释:我的间隔设置:this.task=setInterval(function(){this.refreshData();},300);我的函数在同一个ts文件中:refreshData():void{console.log('update...');}当我在我的设备上运行时,出现此错误:04-1910:38:57.53521374-21374/com.ionicframework.app722890I/chromium:[INFO:CONSOLE(79432)]"TypeError:this.refres