草庐IT

fcatch-undefined-behavior

全部标签

javascript - 简单的 js FOR 循环返回 'undefined'

不确定我在这里做错了什么;变量newStr应该只返回“HelloWorld”,但我得到的是:"undefinedHelloWorld"undefinedJSfunctiontranslate2(x){varnewStr;x="HelloWorld";for(i=0;i 最佳答案 在JavaScript中,如果一个变量没有显式初始化,它默认为undefined。.那不是字符串,而是语言的原始类型。您可以通过打印来检查varnewStr;console.log(newStr);//undefinedconsole.log(newStr+

javascript - a.nodeName is undefined Jquery错误

a.nodeNameisundefined我查过这个,但对我来说解释似乎一点都不清楚。functiondeleteThisRow(){$(this).closest('tr').fadeOut(400,function(){$(this).remove();});}blahblahblah 最佳答案 您函数中的this关键字未引用被单击的元素。默认情况下,它会引用DOM中的最高元素,即window。要解决此问题,您可以使用不显眼的事件处理程序,而不是过时的on*事件属性,因为它们在引发事件的元素的范围内运行。试试这个:$("trtd

javascript - 在javascript中为 undefined variable 设置默认值

理想情况下,我希望能够编写如下内容:functiona(b){b.defaultVal(1);returnb;}这样做的目的是,如果b是任何定义的值,b将保持该值;但如果b未定义,则b将设置为defaultVal()的参数中指定的值,在本例中为1。这可能吗?我一直在玩弄这样的东西:String.prototype.defaultVal=function(valOnUndefined){if(typeofthis==='undefined'){returnvalOnUndefined;}else{returnthis;}};但是我没有成功地将这种逻辑应用于任何变量,尤其是undefine

javascript - 为 Angular JS 启用 html 5 模式会抛出 JS 错误 : Failed to instantiate module due to: TypeError: Cannot read property 'html5Mode' of undefined

如何为AngularJS启用html5模式?'usestrict'varblogApp=angular.module('blogApp',['ngRoute']).config(['$routeProvider',function($routeProvider,$locationProvider){$routeProvider.when('/disclaimer',{templateUrl:'templates/disclaimer.html',controller:'DisclaimerCtrl'});$routeProvider.otherwise({redirectTo:'/'}

javascript - 设置比例(d3,zoom.behavior)后如何发送 'zoom' 事件

在缩放行为上手动设置比例后,如何触发缩放事件?varzoom=d3.behavior.zoom().scaleExtent([0.5,4]).on('zoom',onzoom);//lateronzoom.scale(2);https://github.com/mbostock/d3/wiki/Zoom-Behavior#wiki-scale 最佳答案 首先,您需要将缩放行为附加到SVG对象。同样,您可以在缩放对象上调用缩放功能。varzoom=d3.behavior.zoom().scaleExtent([0.5,4]).on('

javascript - Google Map API V3- MarkerClusterer undefined

我按照库和youtube指南将标记聚类器添加到我的map,但我遇到了问题。MarkerClustererundefined我已按照指南中的说明定义了MarkerClusterer,但仍然出现上述错误。下面是我的代码MaPagedeGoogleMapsV3html,body,#map_canvas{margin:3;padding:3;height:100%;}.tooltip{background-color:#ffffff;font-weight:bold;border:2px#006699solid;width:150px}varscript='';document.write(s

javascript 初始化为 undefined 或 null 或 ""

在我开始学习时,Java脚本有很多错误的值。我有一个从服务获取值并加载到数组中的程序,如下所示:functionloadNames(){Global.names=//whatshouldIusehere?undefined,null,"",0,{}oranythingelsevarlnames=getLNames();//thisisdoingsomemagicif(lnames.length!==0){Global.names=newArray();for(vari=0;i我想知道重置Global.names的正确方法。这里最合适的是什么?在代码中我只想检查if(Global.nam

javascript - 谷歌地图 API v3 - TypeError : Result of expression 'google.maps.LatLng' [undefined] is not a constructor

我正在创建一个静态html页面来显示数据中的多个位置。我刚刚复制了其中一个示例并正在向后工作,但我在Safari检查器中收到以下错误:main.js:1SyntaxError:Parseerrorsample.htm:10TypeError:Resultofexpression'google.maps.LatLng'[undefined]isnotaconstructor.这是我的html代码:MultiMarkersSampleviaGoogleMapsfunctioninitialize(){varmyLatlng=newgoogle.maps.LatLng(-30.2965590

javascript - require.js 未捕获类型错误 : cannot read property '__module_path__; of undefined

所以我刚刚开始尝试掌握require.js,但它似乎不起作用。当我使用标签将其包含在我的html中时:在chrome中加载页面时出现以下错误UncaughtTypeError:Cannotreadproperty'__MODULE_PATH__'ofundefined->require.js:538在firefox中我得到一个稍微不同的错误:TypeError:parentisundefined->require.js:538不知道我怎么会导致这个问题,因为它是require.js的全新安装,我的main.js中还没有代码。提前致谢 最佳答案

javascript - 未捕获的类型错误 : Cannot read property 'focus' of undefined

此问题在我的页面加载时发生。使用以下脚本-jquery.simplemodal-1.4.3.js-jqueryv1.7.1下面是一个小代码快照,是发生此错误的simplemodal内的代码。focus:function(pos){vars=this,p=pos&&$.inArray(pos,['first','last'])!==-1?pos:'first';//focusondialogorthefirstvisible/enabledinputelementvarinput=$(':input:enabled:visible:'+p,s.d.wrap);setTimeout(fun