草庐IT

DB_Variable

全部标签

javascript - Jquery each() : variable in callback always has last value?

似乎无法弄清楚这里发生了什么。DiscoverDocumentationDownloadDonate$('.navItem').each(function(){$link=$(this).children('a');$link.hover(function(){$link.css('width','224px');},function(){$link.css('width','192px');})});http://jsfiddle.net/Sth3Z/它应该为每个链接都这样做,而不是它只更改最后一个链接,无论将鼠标悬停在哪个链接上。 最佳答案

javascript - (typeof variable === "function") 和 jQuery.isFunction() 有什么区别?

我一直使用(typeofvariable==="function")并且偶然发现了jQuery.isFunction()我想知道:typeof方法和jQuery的方法有什么区别?不仅有什么区别,而且什么时候用typeof方法合适,什么时候用jQuery的方法合适? 最佳答案 除了使用jQuery稍慢之外,几乎没有区别。查看源代码:isFunction:function(obj){returnjQuery.type(obj)==="function";},它调用一个函数,该函数调用另一个函数来确定与您显示的完全相同的东西:P在这种情况

javascript - 在javascript中为 undefined variable 设置默认值

理想情况下,我希望能够编写如下内容:functiona(b){b.defaultVal(1);returnb;}这样做的目的是,如果b是任何定义的值,b将保持该值;但如果b未定义,则b将设置为defaultVal()的参数中指定的值,在本例中为1。这可能吗?我一直在玩弄这样的东西:String.prototype.defaultVal=function(valOnUndefined){if(typeofthis==='undefined'){returnvalOnUndefined;}else{returnthis;}};但是我没有成功地将这种逻辑应用于任何变量,尤其是undefine

javascript - 错误 TS2539 : Cannot assign to 'c' because it is not a variable

我有2个.ts文件,C.ts:exportletc:any=10;A.ts:import{c}from"./C";c=100;编译A.ts时报错:errorTS2539:Cannotassignto'c'becauseitisnotavariable.我该如何解决? 最佳答案 将它放在一个类中,并使其成为静态的exportclassGlobalVars{publicstaticc:any=10;}从任何其他文件导入之后GlobalVars.c=100; 关于javascript-错误TS

javascript - Mongoose : Inserting JS object directly into db

好的,我有一个通过AJAX发布到nodejs后端的JS对象。我想将这个js对象直接插入到我的Mongoose数据库中,因为对象键已经与数据库模式完美匹配。我目前有这个(不是动态的并且过于复杂):app.post('/items/submit/new-item',function(req,res){varformContents=req.body.formContents,itemModel=db.model('item'),newitem=newitemModel();newitem.item_ID="";newitem.item_title=formContents.item_tit

javascript - 获取 ReferenceError : Can't find variable: angular

我不熟悉yeoman及其使用的所有工具。我在yeoman中创建了一个测试项目并尝试在jasmine中运行测试规范。我已经使用cmd安装了jasmine插件:npm安装grunt-contrib-jasmine--save-dev在Gruntfile.js中添加了一个jasmine任务jasmine:{src:'/scripts/{,*/}*.js',specs:'test/spec/{,*/}*.js'},当我运行jasmine任务gruntjasmine时出现以下错误:-E:\PersonalProjects\yeoman-projects\test-app>gruntjasmine

javascript - vuejs 配置 : using a global variable?

这看起来很蠢,但我是这样设置的:在config/index.js中:module.exports={API_LOCATION:'http://localhost:8080/api/'}然后在src/app.js我有:importVuefrom'vue'importVueRouterfrom'vue-router'importVueResourcefrom'vue-resource';Vue.use(VueRouter);Vue.use(VueResource);constApp=require("./app.vue");consthome=require("./components/h

javascript - Angular : Select doesn't change selected option on change of bound scope variable

我有一个选择控件。它的选项是从作用域的对象数组动态生成的。在应用程序初始化时,我想通过更改作用域上的绑定(bind)变量来选择特定选项。当select的ng-option返回完整对象时,它不起作用。但是,它在select的ng-option返回字符串时有效。是Angular错误还是我做错了什么?HTML:Doesn'tworkwhenselect'sngModelvalueisobject:{{valueObject|json}}Workswhenselect'sngModelvalueisstring:{{valueString|json}}JS:functionselectCtrl

Javascript 继承 : Parent's array variable retains value

我在这里尝试在JavaScript中使用继承,我发现Parent类中的数组值被Child类继承时出现问题。下面的代码是正常的继承:varParent=function(){this.list=[];};varChild=function(){};Child.prototype=newParent;Child.prototype.constructor=Child;varobj1=newChild;obj1.list.push("hello");console.log(obj1.list);//prints["hello"];当我将新的Child对象(继承包含名为list的数组变量的Pa

javascript - jQuery/JavaScript : Defining a global variable within a function?

我有这个代码:varone;$("#ma1").click(function(){varone=1;})$("body").click(function(){$('#status').html("Thisis'one':"+one);})当我点击正文时,它说:这是“一个”:未定义。如何定义要在另一个函数中使用的全局变量? 最佳答案 从函数内部移除var。$("#ma1").click(function(){one=1;}) 关于javascript-jQuery/JavaScript:D