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?
I tried this but it didn't work (#name is the div I want to put the text in:
$('#name').text(names(this.id));
$('#name').text(names[this.id])
This is not related to jQuery in any way though. 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"]
.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.