草庐IT

something_is_not_right

全部标签

javascript - chrome 扩展在定义的变量上抛出 "not defined"

我正在尝试使用chrome扩展程序访问本地变量。在页面脚本中尝试console.info(myVar)时,我得到myVarisnotdefined但是,当使用chrome开发人员工具并在调试控制台中执行相同的代码片段时,我得到了myVar的全部内容。尝试访问window.myVar时的行为相同,当通过chrome扩展程序打印时,这只是undefined。通过开发工具和页面脚本使用以下代码片段将脚本标记注入(inject)正文,会导致完全相同的行为。$("body").append($("",{html:"console.info(myVar);"}));在开发工具中执行时会打印变量,但

javascript - rails link_to : Do something after confirmation

我正在尝试使用link_to通过AJAX执行保存操作:我希望将链接替换为Saving...确认后,但无法找到一种干净的方法。现有解决方案的问题:禁用:如果我添加:disable_with=>'Saving...'链接的内部HTML将被替换,而不是链接本身。不想这样。点击:如果我添加:onclick=>"$(this).replaceWith('Saving...');"链接将立即被替换,即使用户取消确认是否有适合Rails3UJS最佳实践的解决方案? 最佳答案 你可以使用钩子(Hook)ajax:beforeSend:$('a#my

javascript - "TypeError: ' 未定义 ' is not a function"尝试使用 jQuery UI 时

我正在尝试使用slider()jQueryUI的功能,并不断在控制台中收到以下错误:类型错误:undefined不是函数(计算jQuery('#slider').slider())我确实已正确链接到jQueryUIjavascript和CSS文件-当我查看页面源代码时,它们都在那里。为什么我仍然收到此错误?如果有用的话,我正在使用Rails和一些Bootstrap东西。这是JavaScript代码:$(document).ready(function(){$('#slider').slider();});谢谢这是:NewCompany-OEFortbyOxfordEntrepreneu

javascript - Firefox -- 仅当从 Web Worker 调用时为 "FileReader is not defined"

在Firefox中,以下代码在主浏览器线程中正常运行时可以正常工作--varfr=newFileReader();..但是当从webworker运行时,会抛出以下错误:FileReaderisnotdefined相同的代码在Chrome和Safari中运行良好。对于在Firefox的网络worker中支持FileReader有什么建议吗? 最佳答案 正如adeneo所指出的,WebWorkers中的Firefox似乎根本不支持FileReader。我能够使用FileReaderSync来完成我需要的。

javascript - promise : is . done() 总是执行,即使 .catch() 是?

我的Promise问题我是Promises的新手,我一直在阅读QDocumentation,它说:Whenyougettotheendofachainofpromises,youshouldeitherreturnthelastpromiseorendthechain.我在我的代码中以Q.Promise方式定义了一个Promise,使用以下console.log来注销执行跟踪:functionfoo(){returnQ.Promise(function(resolve,reject){doSomething().then(function(){console.log('1');retu

javascript - 脚本运行时 Heroku 日志警告 "(node) sys is deprecated. Use util instead"

我已经在heroku中部署了一个由调度程序运行的Node脚本。但是当脚本运行时,我在日志中看到一条警告。Dec0711:01:10xxxheroku/scheduler.3255Startingprocesswithcommand`nodebin/script`Dec0711:01:13xxxapp/scheduler.3255:(node)sysisdeprecated.Useutilinstead.我还没有在我的package.json中声明一个engine部分。是不是node版本有问题?我怎样才能避免这个警告?谢谢! 最佳答案

javascript - 诗乃JS : Is there a way to stub a method on object argument's key value in sinon js

我想在以下响应中模拟对obj.key3值的不同响应。就像ifobj.key3=true然后返回与obj.key3=false不同的响应functionmethod(obj){returnanotherMethod({key1:'val1',key2:obj.key3});} 最佳答案 您可以使用.withArgs()和对象匹配器根据调用它的参数使stub返回(或执行)某些操作。例如:varsinon=require('sinon');//Thisisjustanexample,youcanobviouslystubexistingm

javascript - JS : What is 'this' coercion? use-strict 和那个有什么关系?

我在网站上阅读了以下内容:Use-stricthasanadvantage.Iteliminatesthiscoercion.Withoutstrictmode,areferencetoathisvalueofnullorundefinedisautomaticallycoercedtotheglobal.Thiscancausemanyheadfakesandpull-out-your-hairkindofbugs.Instrictmode,referencingaathisvalueofnullorundefinedthrowsanerror.这到底是什么意思?use-strict

javascript - Greybox : Can't move focus to the control because it is invisible, 未启用,或者是不接受焦点的类型

这个问题在这里已经有了答案:关闭10年前。PossibleDuplicate:JavaScript:VisibilityerrorinInternetExplorerwhensettingfocusonaninputelement我有一个在灰框中加载的页面。我使用document.getElementById("textfield").focus()设置焦点-这在直接调用页面时效果很好。但是当在灰盒中加载时,将焦点设置在onload()事件上会返回:Can'tmovefocustothecontrolbecauseitisinvisible,notenabled,orofatypeth

Javascript 正则表达式 : How to get `1` and not `11`

如果我这样做:varstring="7,11,2"varcheck=string.match("/1/");if(check!=null){doSomething();}else{doSomethingElse();}然后check不是null因为match找到了1在11.那么我应该如何避免这种情况并获得1什么时候真正出现? 最佳答案 发生这种情况是因为它匹配11中的1并将其称为匹配项。您必须确保1之后没有其他数字。尝试:varcheck=string.match("/(^|\D)1(\D|$)/");这将寻找一种被非数字字符或字符