草庐IT

a_function_should_be_runned

全部标签

javascript - Chrome 扩展 js : Sharing functions between background. js 和 popup.js

假设我有一个JavaScript函数foo(),我想在后台和popup.html中执行它。例如:它每小时在我的Chrome扩展程序的后台执行一次,但也可以由用户通过单击按钮从弹出菜单(popup.html)激活。我目前有一个定义foo()的global.js脚本,当我在我的中包含对foo()的调用时>popup.js文件,它们可以毫无问题地执行。(如果我在popup.html中包含这两个脚本)但是,当我尝试访问background.js中的foo()时,调用不会执行(即使global.js包含在“后台”“manifest.json”扩展文件中:"background":{"persis

javascript - Angular 1.5 组件 : passing a function

是否可以将函数传递给组件并在传递参数的组件内部调用此函数?例子:帖子列表getPostUrl是一个函数(在容器Controller中):constgetPostUrl=(postId)=>{constprotocol=$location.protocol();consthost=$location.host();constport=$location.port();returnprotocol+"://"+host+""+(port!==80?":"+port:"")+"/blog/post/"+postId;};帖子列表:组件constPostList={"bindings":{"p

javascript - 我所有的 Observables 错误 'takeUntil is not a function'

出于某种原因,我无法在我的任何可观察对象上使用takeUntil方法。我的IDE(VisualStudioCode)在我编码时将其显示为有效方法,并且编译良好(从typescript),但是当我运行它时,我得到takeUntilisnotafunction在我的任何observables上。我使用的是rxjs版本5.3.0。我可以通过多种方式实现它,但这可能是最直接的:letsubject:BehaviorSubject=newBehaviorSubject({});letunsubscribe:Subject=newSubject();subject.takeUntil(unsubs

javascript - 创建一个 jQuery 插件 : best practices regarding functions' visibility?

我正在创建一个jQuery插件。到目前为止它工作正常,但我对我做事的方式有疑问:jQuery.fn.myMethod=function(){returnthis.each(function(){MyScope.doSomething(jQuery(this).attr("id"));});};varMyScope={//ThefunctionscontainedinMyScopeareextremelylinkedtothelogic//ofthispluginanditwouldn'tmakealotofsensetoextractthemdoSomething:function(i

javascript - React JS 未捕获引用错误 : function not defined

我正在尝试在ReactJs组件中发生单击事件时调用shuffleCards。但是,我收到以下错误:UncaughtReferenceError:shuffleCardsisnotdefined这是我的代码:constructor(props){super(props);this.state={count:0};}shuffleCards(array){vari=array.length,j=0,temp;while(i--){j=Math.floor(Math.random()*(i+1));temp=array[i];array[i]=array[j];array[j]=temp;}

javascript - Angular module.run ReferenceError : $location is not defined

我想在不重新加载的情况下改变AngularJS的路径,看http://joelsaupe.com/programming/angularjs-change-path-without-reloading/在core.js中:'usestrict';angular.module('App',['ngRoute']).run(['$route','$rootScope','$location',function($route,$rootScope,$location){varoriginal=$location.path;$location.path=function(path,reload

javascript - JavaScript 中的 var thing 和 function thing() 有什么区别?

我只是想知道以下JavaScript对象声明之间的区别。具体来说,thingobjectliteral和thingclass中的thing1object之间的区别。代码:varthing={sanity:0,init:function(){//code},send:function(){//code}}functionthing(){this.sanity=0;this.init=function(){//code};this.send=function(){//code};}thing1=newthing(); 最佳答案 静态对象

javascript - appendChild 错误 : Node cannot be inserted at the specified point in the hierarchy

appendChild函数出错:无法在层次结构中的指定点插入节点JS:varabc=document.createElement("div");abc.style.position="absolute";abc.style.width="10px";abc.style.height="10px";abc.style.left="10px";abc.style.top="10px";abc.style.backgroundColor="black";abc.innerHTML="abc";document.appendChild(abc);http://jsfiddle.net/T7ZM

javascript - Javascript 中的 !function 是什么意思?

这个问题在这里已经有了答案:Whatdoestheexclamationmarkdobeforethefunction?(8个答案)关闭5年前。很抱歉发布这个,但是!function无法通过google搜索,而且我没有在我的JavaScript代码中找到它。Twitter是这样使用它的:Tweet!function(d,s,id){varjs,fjs=d.getElementsByTagName(s)[0];if(!d.getElementById(id)){js=d.createElement(s);js.id=id;js.src="//platform.twitter.com/wi

Javascript/jQuery : How to prevent active input field from being changed?

如何防止用户在不使用disabled="true"的情况下更改输入字段中的值(其中包含要复制到剪贴板的特定值)?一旦用户在该字段中单击(已经可以正常工作),就应该选择文本,但输入任何内容都不会产生任何效果。谢谢jQuery('input.autoselect[value]').focus(function(){jQuery(this).select();}); 最佳答案 输入html中的readonly是防止用户编辑输入所需的全部内容。 关于Javascript/jQuery:Howto