jQuery变量变量 [英] Jquery variables variable
本文介绍了jQuery变量变量的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
存在一些类似变量变量的概念,以动态显示变量名称或动态调用函数:
There exist some concept like variables variable to print variable names or call functions dynamically:
http://php.net/manual/en/language.variables. variable.php
谢谢.
推荐答案
最接近的JavaScript等效项是方括号符号,例如:
The closest JavaScript equivalent is bracket notation, for example:
var obj = { myMethod: function() { alert("Hello!"); } };
var func = "myMethod";
obj[func](); //equal to obj.myMethod();
您可以在此处进行测试,在JavaScript中调用这两个功能是等效的:
You can test it out here, in JavaScript calling these two is equivalent:
object.property
object["property"];
并且后者允许您使用变量来获取所需的任何属性或方法.
And the latter allows you to use a variable, to get any property or method you want.
为清楚起见,这是一种JavaScript行为,关于jQuery并没有特定的内容.
To be clear this is a JavaScript behavior, there's nothing specific to jQuery about it.
这篇关于jQuery变量变量的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文