[英]Associative arrays in Jquery
If I have an associative array like this: 如果我有这样的关联数组:
var names = { '10watt' : '_ULR', '20watt' : '_ULR', '30watt' : '_ULR', '40watt' : '_ULR', '50watt' : '_ULR', '60watt' : '_ULR', '75watt' : '_ULR', '100watt' : 'ULCR', '120watt' : 'ULCR', '150watt' : 'ULCR' };
how do I write the value of the key to the browser, if the key is this.id? 如果键是this.id,如何将键的值写入浏览器?
I tried this but it didn't work (#name is the div I want to put the text in: 我尝试了这个,但它不起作用(#name是我想把文本放入的div:
$('#name').text(names(this.id));
$('#name').text(names[this.id])
This is not related to jQuery in any way though. 但这与jQuery无关。 In JavaScript, if you have an object
obj
, then you can access its property prop
either like this obj.prop
, or like this obj["prop"]
. 在JavaScript中,如果你有一个对象
obj
,那么你可以像这个obj.prop
一样访问它的属性prop
,或者像这个obj["prop"]
。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.