草庐IT

function_find-in-set

全部标签

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 - JS 日期 : Add 0 in front of every single day or month

我将此日期从api解析为字符串:DD-MM-YYYY但有时日期是DD-M-YYYY甚至D-M-YYYY。例如:2013年4月1日要么10-10-2013或7-4-2013年份始终为4位数,但日或月有时为一位数。如何手动(使用JS)在每个数字前添加0?我正在使用moment.js进行一些计算,因此我使用删除了“-”date.replace("-","")得到一个整数(例如4-1-2013=412013),这样我就可以将它与moment.js一起使用,但如果它是一个数字,一切都会变得一团糟。 最佳答案 您可以像这样首先规范化您的字符串:

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 - 在 javascript 中正确使用 "for...in"循环?

在我提出问题之前,我想让每个人都知道,我很感激总有人愿意提供帮助这一事实,而在我这边,我会尽我所能回馈社区。谢谢现在,我想获得一些关于如何正确利用JavaScript中的“for...in”循环的指示,我已经做了一些研究并尝试了一些事情,但我仍然不清楚如何正确使用它。假设我在HTML表单中有随机数量的“选择”标签,我不要求用户为所有标签选择一个选项,如果他们愿意,他们可以保留一些不变。但是我需要知道他们是没有选择还是至少选择了一个。我试图找出用户是否选择了其中任何一个的方法是使用“for...in”循环。例如:varallSelected=$("selectoption:selecte

javascript - Uncaught Error : No Storage Bucket defined in Firebase Options.(网络)

我试图在firebase存储上上传文件(图像)。但它会显示一条错误消息“UncaughtError:Firebase选项中未定义存储桶。”.这是我的代码constfileUpBtn=document.getElementById('photoUpload');constselectFile=document.getElementById('selectedFile');constpostIt=document.getElementById('postIt');fileUpBtn.addEventListener('click',function(){selectFile.click()

javascript - JS : new Date() is not accepting date string in my own locale (d/m/y)

我的浏览器(即我的操作系统)应该知道我在澳大利亚以及正确的日期格式是什么。在这种情况下,d/m/y,而不是m/d/y。但是,如果我运行以下代码:alert(newDate("21/11/1968"))结果是“1969年9月11日星期四”。它认为月份在前,并相应地进行调整。这是为什么?答案是始终使用通用格式作为日期函数的输入,还是有办法告诉浏览器期望以我的语言环境格式输入日期? 最佳答案 将日期字符串转换为可提供预期结果的格式(“yyyy/mm/dd”或“yyyy-mm-dd”)非常简单:newDate("21/11/1968".sp

javascript - Angular JS : binding in ng-show not working

我有一个指令和一个Controller:app.directive('responseBox',function(){return{restrict:'E',transclude:true,templateUrl:'responseBox.html',link:function(scope,element,attrs){element.bind("click",function(){scope.toggle();})}}});和一个Controller:app.controller('responseBoxCtrl',function($scope){$scope.opened=fal