草庐IT

send_this_email

全部标签

javascript - 在 setTimeout() 中使用 $(this);

我想在jQuery中动态设置超时。动态设置超时函数需要使用$("this"),但我似乎无法让它工作。一个例子:$("div").each(function(){varcontent=$(this).attr('data-content')setTimeout("$(this).html('"+content+"')",$(this).attr('data-delay'));});​http://jsfiddle.net/qmhmQ/执行此操作的最佳方法是什么? 最佳答案 $("div").each(function(){varcon

javascript - 在外部函数中使用 $(this)

我是JavaScript的新手,我想知道为什么它对我不起作用:functionresetColor(){$(this).css({"color":"red"})}$('.class').click(function(){resetColor();});我还尝试在单击.class时将$(this)保存为变量,但这对我也不起作用。 最佳答案 一种更简单的方法是引用函数而不是将其包装在匿名函数中,如下所示:$('.class').click(resetColor); 关于javascript-

javascript - React Native 中的 Websocket.send(blob)

我正在尝试在ReactNative中使用Websocket发送blob数据。我的Reactnative和web代码如下:varwebsocket=newWebSocket(this.state.wsURI);websocket.onopen=function(evt){onOpen(evt)};websocket.onclose=function(evt){onClose(evt)};websocket.onmessage=function(evt){onMessage(evt)};websocket.onerror=function(evt){onError(evt)};functi

javascript - 如果 "this"为空字符串,则 Handlebars 中的 {{#each this}} 不起作用

考虑我的json是这样的:{main:{"":[{some_obj},{some_obj}]},secondary:{"key":[{some_obj},{some_obj}]}}现在我的第一个#each将运行在主要和次要的地方。{{#eachthis}}--Thisisformainandsecondary--{{#eachthis}}--Thisisfor""incaseofmainand"key"incaseofsecondary--{{/each}}{{/each}}如果“this”为空,如我的“main”属性的json中所示,我的嵌套#each将不起作用

javascript - 访问 promise 回调中对象的 'this'(然后)

我想用Javascript创建一个对象。其中一个方法应该执行一个promise链。链中的每个方法都必须访问作为对象成员的配置变量。问题是,this运算符在PromiseMethod2中被更改,我无法访问配置变量(它在PromiseMethod1中正常工作)。这是我的代码:varSomeObject(config){varthat=this;that.config=config;}SomeObject.prototype.SomeMethod=function(){varthat=this;that.PromiseMethod1().then(that.PromiseMethod2).c

javascript - VueJs v-on :event and this. $on(event, handler) 有什么区别?

我正在学习Vuejs事件处理。我认为开发人员可以使用this.$on('event',handler)在js文件中处理'event'。有一个example.EmitEventjs文件varapp=newVue({el:"#mainapp",data:{show:false},created:function(){this.$on('event',this.processEvent);},methods:{emitEvent:function(){this.$emit('event',{data:'mydata'});},processEvent(data){console.log('j

javascript - 嵌套函数中的函数上下文 ("this")

当您在Javascript中调用顶级函数时,函数内的this关键字指的是默认对象(如果在浏览器中则为window)。我的理解是,调用函数作为方法是一种特殊情况,因为默认情况下它是在窗口上调用的(如JohnResig的书《JavaScript忍者的secret》第49页中所述)。事实上,以下代码中的两个调用是相同的。functionfunc(){returnthis;}//invokeasatop-levelfunctionconsole.log(func()===window);//true//invokeasamethodofwindowconsole.log(window.func

javascript - TypeError : jQuery. easing[this.easing] 不是函数

这个问题在这里已经有了答案:TypeError:p.easing[this.easing]isnotafunction(12个答案)关闭6年前。我需要为我的jQuery链接添加一个效果,但它只适用于最低1.7.1,而我有另一个代码只适用于1.10.2。此代码仅适用于1.10.2$(document).ready(function(){varmenu=document.querySelector('#menu-bar-wrapper');varorigOffsetY=menu.offsetTop;functionscroll(){if($(window).scrollTop()>=ori

改变 this.style.backgroundImage 的 Javascript

给定以下代码,我将如何完成tileClick()以便将点击的图像从“tileBack.jpg”更改为显示分配给该特定div的图像在shuffleDeck()中?我的意思是,tileClick()函数应该获取当前显示tileBack图像的图block,并在单击时显示该图block“反面”的图像.到目前为止,您可以看到我是如何尝试定位被单击的特定磁贴的,尽管我不确定此处是否正确使用了this.。在该声明的另一边,我尝试做类似="../img/tile_"+tiles[i]+".png";的事情,但显然问题在于i不存在于该函数的范围内。我的问题是我不知道如何重构我的代码,以便我可以访问以前分

javascript - 在这段代码中,为什么 foo 和 this.foo 指的是不同的东西?

代码如下:for(vari=0;i为什么i和this.i指的是不同的东西?将此与在全局范围内执行的一些代码进行对比:varx=5;console.log(x);console.log(this.x);//bothwillprint5这里的范围是全局的,上下文也是。变量声明在全局上下文中设置同名属性。另一方面,在函数范围内,这不会发生。vara=function(){varx=5;console.log(x);//5console.log(this.x);//undefinedconsole.log(i);//undefinedconsole.log(this.i);//10}.bind