草庐IT

Regex-replace-with-function-evalu

全部标签

JavaScript 符号 : (function() { . .. } )();

这个问题在这里已经有了答案:关闭11年前。PossibleDuplicate:WhatisthepurposeofwrappingwholeJavascriptfilesinanonymousfunctionslike“(function(){…})()”?大家好,我见过几个使用这种表示法的JavaScript文件:JavaScript文件的开始:(function(){//Allfunctionsgohere.//Cansomeonesaywhatthewrappingnamelessfunctionisusedfor?})();还有原型(prototype)库,这似乎是可能的:fu

javascript - 对象没有方法 'replace'

我尝试运行这个函数,它将所有选中的复选框值抓取到逗号分隔的字符串中,并将","转换为",",所以它读起来更好。问题是我遇到了一个奇怪的错误:$('.name_boxes').live('click',function(){varall_boxes=$('.name_boxes');varall_boxes_values=[]for(vari=0;i控制台错误说:UncaughtTypeError:ObjectAaronRamsey,AaronRenfreehasnomethod'replace'.我没有收到警告框。这有点超出我的理解范围,有人可以解释我做错了什么吗?

javascript - NodeJs 使用 ExpressJs : TypeError: string is not a function at Function. app.render

我刚开始学习Node,我正在尝试使用Node和Express构建Web应用程序。我的app.js文件中有以下代码,具有以下目录结构。目录结构:appassetscontrollermodelviewindex.jadeglobalnode_modulesapp.jspackage.json-js-varexpress=require('express');varapp=express();app.configure(function(){app.set('view',__dirname+'/app/view');app.set('viewengine','jade');app.use(

javascript - 类型错误 : getState is not a function when adding middleware to Redux

在我的configureStore.dev.js文件中使用此代码,在添加applyMiddleware(reduxImmutableStateInvariant)时,我得到一个UncaughtTypeError:getStateisnotafunction。当我删除这个添加的中间件时,我的项目运行正常。添加此中间件的正确方法是什么?这是完整的文件:import{createStore,compose,applyMiddleware}from'redux';importrootReducerfrom'../reducers';importreduxImmutableStateInvari

javascript - Cloud Functions for Firebase 组织

我知道有人问过这个问题here,但它没有回答我的问题。我的问题是我们如何为CloudFunctions分解index.js,包括onWrite调用等。我知道您可以使用“require”并引入外部代码。它仍然在index.js中留下一些代码(例如,在FranksOCR示例中)。理想情况下,我希望能够将整个onWrite事件触发器移动到另一个文件。index.js中的示例:exports.sysQueueUserNew=functions.database.ref("/sys/queue/user_new/{queueId}").onWrite((event)=>{//dosomethin

如果字符串包含不在 RegEx 中的字符,则返回 Javascript RegEx

我有一个用户创建的字符串。我只允许字符A-Z、a-z、0-9、-、和_使用JavaScript,我如何测试字符串是否包含不是这些字符?如果字符串包含不是这些字符,我想提醒用户这是不允许的。我可以使用哪些Javascript方法和RegEx模式来匹配它? 最佳答案 您需要使用否定字符类。将以下模式与matchfunction一起使用:[^A-Za-z0-9\-_]例子:varnotValid='Thistextshouldnotbevalid?';if(notValid.match(/[^A-Za-z0-9\-_]/))alert('

javascript - string.replace 在 node.js Express 服务器中不起作用

我需要读取一个文件并用动态内容替换该文件中的一些文本。当我尝试string.replace时,它​​不适用于我从文件中读取的数据。但对于它正在工作的字符串。我是使用node.js和express。fs.readFile('test.html',functionread(err,data){if(err){console.log(err);}else{varmsg=data.toString();msg.replace("%name%","myname");msg.replace(/%email%/gi,'example@gmail.com');temp="Hello%NAME%,wou

javascript - Angular JS 类型错误 : $http is not a function

我已经阅读了所有人们遇到$http不是函数的问题的帖子,看起来大部分是由于注入(inject)顺序错误所致。我的模块定义如下:angular.module("app",[]).controller("appCtrl",['$scope','$http',function($scope,$http){...$scope.makeCall=function($http){console.log("HERE");$http({method:'GET',url:如有任何建议,我们将不胜感激。 最佳答案 从makeCall函数中删除$http

javascript - 学习 JavaScript : display all firstnames with B as first letter

我是第一次学习JavaScript,我想知道为什么我的代码不起作用。我有Python/Django知识。目标:我必须创建一个姓名列表,并且我必须只显示以“B”字母开头的名字。我的脚本:varlistNames=['Paul','Bruno','Arthur','Bert','José']for(variinlistNames){if(i.substr(0,1)==='B'){console.log(i);}}但是这段代码没有显示任何东西。 最佳答案 您需要使用listNames[i]作为i为您提供数组listNames的index。

javascript - jQuery .fn 表示 "not a function"

当我调用这个自定义函数时$.fn.inputBoxHelper=function(){varargs=arguments[0]||{};varmatchingElem=$.grep(this,function(e){return$(e).val()==$(e).attr('title');});$(matchingElem).addClass(args.className);this.bind({focus:function(){if($(this).val().trim()==$(this).attr('title')){$(this).val(emptyString).remove