草庐IT

the_string

全部标签

javascript - 为什么 String.prototype 的方法可用于字符串文字?

这个问题出自another,它涉及console.dir与字符串文字的行为。特别是,请参阅关于myanswer的评论.众所周知,JavaScript中的String对象有很多方法。这些方法在String.prototype对象上定义。String.prototype.toUpperCase例如。因此,我们可以这样做:vars=newString("hello"),s2=s.toUpperCase();//toUpperCaseisamethodonString.prototype不过,我们也可以这样做:vars="hello",//sisastringliteral,notaninst

javascript - D3 过渡 : Fading in and out the colors within a gradient fill

在这个D3图中,圆圈填充了径向渐变,并且改变不透明度用于淡入和淡出:varwidth=400,height=400,padding=1.5,//separationbetweensame-colornodesclusterPadding=6,//separationbetweendifferent-colornodesmaxRadius=12;varn=200,//totalnumberofnodesm=10;//numberofdistinctclustersvarcolor=d3.scale.category10().domain(d3.range(m));//Thelargest

javascript - 逗号分隔值 : from strings to objects to list

我有3个变量,它们的字符串包含逗号分隔值(我不知道有多少),我想将它们合并到jQuery对象中。"name1,name2,name3,nameN""value1,value2,value3,valueN""id1,id2,id3,idN"到:varitem1={name:name1,value:value1,id:id1};varitem2={name:name2,value:value2,id:id2};varitem3={name:name3,value:value3,id:id3};varitemN={name:nameN,value:valueN,id:idN};然后对每个项目

javascript - jQuery.contents() 获取每个元素作为 HTML/STRING

我正在尝试使用jquery内容获取某些对象(包括文本)的HTML形式。这是我到目前为止得到的:HTMLtestfoobarjQuery$('#mydiv').contents().each(function(){console.log($(this).html());console.log($(this).prop("innerHTML"));console.log($(this).prop("outerHTML"));});有什么办法吗?我四处搜寻,但找不到任何东西。预先感谢您的回答! 最佳答案 如果您正在寻找包含包装元素的htm

javascript - VueJS : How to Access the Previous Item in v-repeat

我有一个表,它从LaravelAPI获取一些JSON来填充行。我正在使用VueJS和v-repeat:@{{entry.id}}@{{entry.distance}}km@{{entry.consumption}}l@{{getPrice(entry)+'€'}}@{{getCost(entry)+'€'}}@{{getAverageConsumption(entry)+'l'}}@{{getAverageCost(entry)+'€'}}@{{getCostPerDay(entry)+'€'}}@{{this.getDate(entry)}}现在我想计算AverageCostPerD

javascript - Angular $state.go {重新加载 : true} shouldn't reinitialize the abstract parent controller

我正在使用ui-route进行导航。我的父状态称为ma​​in,它是一个abstract状态(url:/main)和子状态products和用户(网址:/main/products和/main/users)。app.config(["$stateProvider","$urlRouterProvider",function($stateProvider,$urlRouterProvider){$urlRouterProvider.otherwise("/main/products");$stateProvider.state("main",{url:"/main",templateUr

javascript - 什么是 "string math",为什么不好?

我最近因为在我编写的应用程序中使用“字符串数学”而受到一位开发人员的斥责。我对整个开发过程还很陌生,没有接受过正规培训,也没有听说过这个问题。这是什么?有问题的代码:$('.submit-input').click(function(){varvalid=true;$('input,select,radio').removeClass('error');$('.error-message').hide();$('.validate').each(function(){if($(this).val()==$(this).attr('default')){valid=false;$(thi

javascript - Crockford 的 hanoi 函数(来自 "The Good Parts")

这个问题在这里已经有了答案:HowdoesrecursivealgorithmworkforTowersofHanoi?(2个答案)关闭8年前。目前,我正在阅读道格拉斯·克罗克福德(DouglasCrockford)的书,汉诺塔的功能让我有点头疼。即使在控制台上记录了一些东西,我也无法真正理解发生了什么。这是我添加的功能:varhanoi=function(disc,src,aux,dst){console.log(disc);console.log(src,dst);if(disc>0){hanoi(disc-1,src,dst,aux);console.log('Movedisc'

javascript - 在 coffeescript 中以编程方式调用函数/"by string"

这个问题在这里已经有了答案:关闭9年前。PossibleDuplicate:Dynamicobjectpropertyname我有一个函数需要根据用户输入的数据调用。例如,我有:models.catmodels.dog现在,我希望能够调用models.[my_str],其中my_str="snake"。所以计算机会认为它正在尝试执行models.snake。有没有办法在javascript或更好的coffeescript中做到这一点?

javascript - 带 RequireJS 的 Underscore.string

我正在尝试同时使用Underscore和Underscore.string与RequireJS.main.js的内容:require.config({paths:{'underscore':'//cdnjs.cloudflare.com/ajax/libs/underscore.js/1.4.4/underscore-min','underscore-string':'//cdnjs.cloudflare.com/ajax/libs/underscore.string/2.3.0/underscore.string.min',},shim:{'underscore':{exports: